Created
February 6, 2019 01:15
-
-
Save stwilz/617ede89f5fc107433f16846abd7e2fb to your computer and use it in GitHub Desktop.
Set nested properties in React without destructuring
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 set from 'lodash/set'; | |
import React from 'react'; | |
export default class extends React.Component { | |
setStateIn = (path, value, fn) => | |
this.setState(state => set(state, path, value), fn); | |
render = () => <div />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment