-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wuping
committed
Feb 23, 2024
1 parent
9b3828c
commit 91bf205
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Context } from './useContext'; | ||
|
||
const contextChild = () => { | ||
return ( | ||
<div> | ||
<h1>Context Child</h1> | ||
<Context.Consumer> | ||
{ | ||
(value) => { | ||
return <h2>{value.test}</h2> | ||
} | ||
} | ||
</Context.Consumer> | ||
|
||
</div> | ||
); | ||
} | ||
|
||
export default contextChild; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createContext } from "react"; | ||
import ContextChild from "./contextChild"; | ||
|
||
type contextTheme = { | ||
test: string | null | ||
} | ||
|
||
export const Context = createContext<contextTheme>({ | ||
test: null | ||
}); | ||
|
||
const useContextCase = () => { | ||
return ( | ||
<div> | ||
useContextCase | ||
<Context.Provider value={{ | ||
test: '111' | ||
}}> | ||
<ContextChild /> | ||
</Context.Provider> | ||
</div> | ||
) | ||
} | ||
|
||
export default useContextCase; |