Answer the question
In order to leave comments, you need to log in
Why doesn't the storage state change?
I have a simple SPA - two buttons and text. There is a repository that for some reason does not change its state. I do not understand why.
Here is the code - everything is trivial. You can run: here code
import React from 'react';
import { render } from 'react-dom';
import { createStore } from 'redux'
// REDUX reducer
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
// Create REDUX store.
// In arguments we need to give reducer
const store = createStore(counter)
// TODO: use this component to view text on a screen
const Counter = ({
value,
onInc,
onDec
}) => (
<div>
<h1>{value}</h1>
<button onClick={onInc}>+</button>
<button onClick={onDec}>-</button>
</div>
)
class App extends React.Component {
render() {
return (
<div>
<Counter
value={store.getState()}
onInc={() => store.dispatch(
{type: 'INCREMENT'})
}
onDec={() => store.dispatch({
type: 'DECREMENT'
})}
/>
</div>
)
}
}
render(<App />, document.getElementById('root'));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question