Skip to content

Instantly share code, notes, and snippets.

@sultan99
Last active February 8, 2023 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sultan99/13ef56b4089789a8d115869ee2c5ec47 to your computer and use it in GitHub Desktop.
Save sultan99/13ef56b4089789a8d115869ee2c5ec47 to your computer and use it in GitHub Desktop.
Example
import {compose} from 'redux'
import {store} from './store.js'
const pickSelectedUser = props => {
const {selectedName, users} = props
const foundUser = users.find(user => user.name === selectedName)
return foundUser.id
}
const deleteUser = userId => event => {
event.preventDefault()
store.dispatch({
type: `DELETE_USER`,
userId,
})
}
// The compose function creates a new function that accepts a parameter.
// The parameter will be passed throw the functions from down to top.
// Each function will change the value and pass it to the next function
// By changing value it was not meant a mutation
const handleClick = compose(
deleteUser,
pickSelectedUser,
)
const Confirm = props => (
<div>
<h1>Are you sure to delete?</h1>
<button onClick={handleClick(props)}>
Delete
</button>
</div
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment