This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (state=null, action)=>{ | |
if (action.type === 'GENERATE_NUMBER'){ | |
return action.payload; | |
} | |
return state; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore} from 'redux'; | |
import App2 from './components/App2'; | |
const store = createStore(reducers); | |
ReactDOM.render( | |
<Provider store={store}> | |
<App2/> | |
</Provider>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const generateRandom = () => { | |
// An action, which return a new random number. | |
return { | |
type:'GENERATE_NUMBER', | |
payload:parseInt(Math.random()*100) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
function App() { | |
const [number, generateRandom] = useState(0); | |
const onButtonClick =() => | |
{ | |
const newNumber = parseInt(Math.random()*1000); | |
generateRandom(newNumber); | |
} | |
return ( |