Skip to content

Instantly share code, notes, and snippets.

@gokhancerk
Last active November 23, 2021 07:09
Show Gist options
  • Select an option

  • Save gokhancerk/9b6b55872fd6d8230213e74afd40e92a to your computer and use it in GitHub Desktop.

Select an option

Save gokhancerk/9b6b55872fd6d8230213e74afd40e92a to your computer and use it in GitHub Desktop.
react-redux cheetsheet
// reducer
const person = {
name: '',
age: '',
national:''
}
export const personReducer = (state = person, action) => {
switch (action.type) {
case 'NAME':
return {...state, name: action.payload}
default:
return state;
}
}
// store/index.js
import {createStore} from 'redux
export const store = createStore(reducer)
// src/index.js
import {Provider} from 'react-redux'
import {store} from 'store/'
<Provider store={store}>
<App />
</Provider>
// App.js
import {useDispatch, useSelector} from 'react-redux'
const name = useSelector(state => state.name);
const dispatch = useDispatch()
dispatch({type:'name', payload: 'Alex'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment