Created
June 22, 2020 15:57
-
-
Save I-keep-trying/8cb23d29aca3fc926b942338cba7225f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useDispatch } from 'react-redux' | |
const App = () => { | |
const dispatch = useDispatch() | |
//works as expected | |
const good = () => { | |
dispatch({ | |
type: 'GOOD', | |
}) | |
} | |
//does not work | |
const goodAction = (payload) => { | |
return { | |
type: 'GOOD', | |
payload, | |
} | |
} | |
return ( | |
<div> | |
{/* works as expected */} | |
<button onClick={good}>good</button> | |
{/* Error: Actions must be plain objects. Use custom middleware for async actions. */} | |
<button onClick={() => dispatch(goodAction)}>good</button> | |
<div>good {state.good}</div> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment