Skip to content

Instantly share code, notes, and snippets.

View archi14's full-sized avatar

Archita Mittal archi14

  • Delhi, India
View GitHub Profile
@archi14
archi14 / NumberReducer.js
Created February 11, 2022 08:44
number reducer
export default (state=null, action)=>{
if (action.type === 'GENERATE_NUMBER'){
return action.payload;
}
return state;
}
@archi14
archi14 / index.js
Created February 11, 2022 08:39
Redux store
import { createStore} from 'redux';
import App2 from './components/App2';
const store = createStore(reducers);
ReactDOM.render(
<Provider store={store}>
<App2/>
</Provider>,
@archi14
archi14 / index.js
Last active February 11, 2022 09:42
action-creator
export const generateRandom = () => {
// An action, which return a new random number.
return {
type:'GENERATE_NUMBER',
payload:parseInt(Math.random()*100)
}
}
@archi14
archi14 / App.js
Created February 2, 2022 11:09
Hooks
import React, {useState} from 'react';
function App() {
const [number, generateRandom] = useState(0);
const onButtonClick =() =>
{
const newNumber = parseInt(Math.random()*1000);
generateRandom(newNumber);
}
return (