Last active
February 8, 2023 19:06
-
-
Save sultan99/13ef56b4089789a8d115869ee2c5ec47 to your computer and use it in GitHub Desktop.
Example
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 {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