doc: add StateProvider and StateValue
This commit is contained in:
1 parent
0ecc546f6c
commit
cffbed42a5
1 file changed
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import React, { createContext, useContext, useReducer } from "react";
|
||||||
|
|
||||||
|
export const StateContext = createContext();
|
||||||
|
|
||||||
|
export const StateProvider = ({ reducer, initialState, children }) => (
|
||||||
|
<StateContext.Provider value={useReducer(reducer, initialState)}>
|
||||||
|
{children}
|
||||||
|
</StateContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const useStateValue = () => useContext(StateContext);
|
||||||
Reference in new issue
Block a user