Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save I-keep-trying/8cb23d29aca3fc926b942338cba7225f to your computer and use it in GitHub Desktop.
Save I-keep-trying/8cb23d29aca3fc926b942338cba7225f to your computer and use it in GitHub Desktop.
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