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 from 'react'; | |
import {useSelector, connect} from 'react-redux'; | |
import * as actions from '../actions/actions'; | |
const App = props => { | |
const {increment, decrement} = props; | |
const count = useSelector(store => store.count); | |
return ( | |
<div> |
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 from 'react'; | |
import {connect} from 'react-redux'; | |
import * as actions from '../actions/actions'; | |
const App = props => { | |
const {count, increment, decrement} = props; | |
return ( | |
<div> | |
<h1>The count is {count}</h1> |
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 from 'react'; | |
import * as actions from '../actions/actions'; | |
import {useSelector, useDispatch} from 'react-redux'; | |
const App = () => { | |
const dispatch = useDispatch(); | |
const count = useSelector(store => store.count); | |
return ( | |
<div> |
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 from 'react'; | |
import {connect} from 'react-redux'; | |
import * as actions from '../actions/actions'; | |
class App extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { |
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 from 'react'; | |
import {render} from 'react-dom'; | |
import App from './components/App.jsx'; | |
import {Provider} from 'react-redux'; | |
import store from './reducers/counterReducer'; | |
render( | |
<Provider store={store}> | |
<App /> | |
</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
import { createStore } from 'redux'; | |
const initialState = { | |
count: 0 | |
} | |
const counterReducer = (state = initialState, action) => { | |
switch(action.type) { | |
case 'CHANGE_COUNT': | |
return { |
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 increment = count => ({ | |
type: 'CHANGE_COUNT', | |
payload: count + 1 | |
}); | |
export const decrement = count => ({ | |
type: 'CHANGE_COUNT', | |
payload: count - 1 | |
}); |