1.0.0 • Published 6 years ago
@abdulghani/reduxcontext v1.0.0
Redux Context setup
In this project there's several component you could import to your project to use
- AppContextProvider
defaultproviding context to it's children and specify reducer to use - useSelector
namedfunction for selecting/get the state value from the context state - useDispatch
namedfunction for dispatching actions to your context's reducer
Usage
You can use it this way
// import your deps
import AppContextProvider from "@abdulghani/reduxcontext";
import myReducer from "somewhere";
const App = () => {
return (
<AppContextProvider reducer={myReducer}>
<MyApp/>
</AppContextProvider>
)
}And you can access the state from your component this way
// other imports
import {useSelector, useDispatch} from "@abdulghani/reduxcontext"
const MyView = () => {
const state = useSelector(state => state);
const dispatch = useDispatch();
useEffect(() => {
// do something in initial render
dispatch({ type: "MY_ACTION", data: "SOME DATA" });
}, [])
}1.0.0
6 years ago