Skip to content

Instantly share code, notes, and snippets.

@stwilz
Created February 6, 2019 01:15
Show Gist options
  • Save stwilz/617ede89f5fc107433f16846abd7e2fb to your computer and use it in GitHub Desktop.
Save stwilz/617ede89f5fc107433f16846abd7e2fb to your computer and use it in GitHub Desktop.
Set nested properties in React without destructuring
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