Skip to content

Commit

Permalink
Removed initState from Provider parameters to eliminate extra boilerp…
Browse files Browse the repository at this point in the history
…late. More common approach of pulling in initState from lexical scope applied
  • Loading branch information
gitdagray committed Dec 29, 2022
1 parent 7004202 commit f3e979a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lesson15/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Counter from "./Counter"
import { CounterProvider } from "./context/CounterContext"
import { initState } from "./context/CounterContext"

function App() {

return (
<>
<CounterProvider count={initState.count} text={initState.text}>
<CounterProvider>
<Counter>{(num: number) => <>Current Count: {num}</>}</Counter>
</CounterProvider>
</>
Expand Down
6 changes: 3 additions & 3 deletions lesson15/src/context/CounterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type StateType = {
text: string;
}

export const initState: StateType = { count: 0, text: '' }
const initState: StateType = { count: 0, text: '' }

const enum REDUCER_ACTION_TYPE {
INCREMENT,
Expand Down Expand Up @@ -64,8 +64,8 @@ type ChildrenType = {
}

export const CounterProvider = ({
children, ...initState
}: ChildrenType & StateType): ReactElement => {
children
}: ChildrenType): ReactElement => {
return (
<CounterContext.Provider value={useCounterContext(initState)}>
{children}
Expand Down

0 comments on commit f3e979a

Please sign in to comment.