NOTE: YOU HAVE TO READ REDUX ARTICLE AT FIRST
npm i redux react-redux
const reducer = (state = initState , action) => {
//some actions logic
return state;
}
import {createStore} from 'redux';
const store = createStore(reducer);
export default store;
import {Provider} from 'react-redux';
<Provider store={store}>
<App />
</Provider>
import {useSelector} from 'react-redux';
// the callback function work like .map callback function
const state = useSelector((state) => {return state});
import {useDispatch} from 'react-redux';
// the callback function work like .map callback function
const dispatch = useDispatch();
dispatch({type:"type-1"})
Existing App
npm install @reduxjs/toolkit
New App
npx create-react-app my-app --template redux
import { createSlice } from '@reduxjs/toolkit'
const mySlice = createSlice({
name:'slice-name',
initialState:{
value:0
},
reducers:{
increment:(state , action) => {
state.value++
},
decrement:(state , action) => {
state.value--;
}
}
});
import { createStore } from '@reduxjs/toolkit'
const store = createStore(mySlice.reducers);
import {useDispatch} from 'react-redux';
const dispatch = useDispatch();
dispatch(mySlice.actions.increment(payload));
import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './counterSlice';
import showAndHideReducer from './showAndHideSlice';
const store = configureStore({
reducer: {
counter: counterReducer,
showAndHide: showAndHideReducer
}
});
export default store;
Login pageSignup pageHome pageList frindesAdd friend + invite friendJoin puplic gameCreate new gameGame roomGame show ruleGame room silent statusGame room discussionGame room voteGame room vote resultVictoryGame points + repeat game or back homeRank page
Nov 30, 2023grades
Sep 2, 2023index -> charts and statistics
Jul 24, 2023CORE MODULES GLOBALS global classes example (Math class) cont val = Math.abs(-5); global functions example (fetch) fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Jun 4, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up