Skip to content

Instantly share code, notes, and snippets.

View bashidagha's full-sized avatar
🎯
Focusing

FaRsHiD bashidagha

🎯
Focusing
  • Tehran, Iran
  • 15:10 (UTC +03:30)
View GitHub Profile
import {createStore} from 'redux'
import {Provider} from 'react-redux'
import Header from './Header'
const initialState = {username : "Farshid"};
const returnStateReducer = (state= initialState, action) =>{
if(action.type === "updateUser"){
return {...state, username : "Farhad"};
import {useDispatch, useSelector} from 'react-redux'
const Header = ()=> {
const user = useSelector((state) => state.username);
const dispatch = useDispatch();
return (
<div>{user}
<input onChange={(e)=> dispatch({type: "updateMyName", payload: e.target.value}) }>
</input>
import {useDispatch, useSelector} from 'react-redux'
const Header = ()=> {
const user = useSelector((state) => state.username);
const dispatch = useDispatch();
return (
<div>{user}
<button onClick={()=> dispatch({type: "updateUser"})}>Change User</button>
</div>
const App= () => {
return <div><h1>Hello World</h1></div>
)}
export default App;
import {createStore} from 'redux'
const store =createStore();
const App= () => {
return (
<div>
<h1>Hello World</h1>
</div>
)
}
import {createStore} from 'redux'
const initialState = {username : "Farshid"};
const returnStateReducer = (state= initialState) =>{
return state;
}
const store =createStore(returnStateReducer);
const App= () => {
return (
<div>
import {createStore} from 'redux'
import {Provider} from 'react-redux'
const initialState = {username : "Farshid"};
const returnStateReducer = (state= initialState) =>{
return state;
}
const store =createStore(returnStateReducer);
const App= () => {
return (
const Header = ()=> {
return (
<div> Header </div>
)}
export default Header
import {createStore} from 'redux'
import {Provider} from 'react-redux'
import Header from './Header'
const initialState = {username : "Farshid"};
const returnStateReducer = (state= initialState) =>{
return state;
}
const store =createStore(returnStateReducer);
const App= () => {
const Header = ()=> {
const user = useSelector((state) => state.username);
return (
<div>{user} </div>
)
}
export default Header