score:3
Accepted answer
you could destructure out the value from the event and just do the setstate
as the only statement.
({ target: { value } }) => this.setstate(prevstate => ({
form: {
...prevstate.form,
password: value
}
}));
score:1
personally i would use this:
e => {
let value = e.target.value;
this.setstate({
form: {
...this.state.form,
password: value
}
});
}
score:1
just another idea for you :)
event => {
const password = event.target.value;
const form = { ...this.state.form, password };
this.setstate({ form });
}
Source: stackoverflow.com
Related Query
- Preferred ES6 arrow function syntax formatting
- Why is arrow syntax preferred over function declaration for functional React components?
- setTimeout ReactJS with arrow function es6
- React.createClass vs. ES6 arrow function
- Reactjs setState arrow function syntax
- Chained Arrow function syntax
- Arrow function syntax in React stateless components
- ES6 Arrow function without curly braces
- How to test arrow function in React ES6 class
- JSX syntax arrow function inside render
- Babel throws a syntax error on arrow function
- Difference between this ES6 arrow function and regular function?
- es6 arrow function in class property
- Are there any functional differences between using fat arrow syntax or not for ES6 class methods and React?
- Arrow function syntax with parentheses instead of curly braces?
- Es6 React Arrow function behaviour
- Javascript Syntax - Arrow function for class
- How to make a use of arrow function in es6 instead of bind method
- Have clarification about syntax of arrow function while iterating data in react's render function
- React / ES6 - Why calling a function inside another only works with es6 arrow functions?
- Getting an arrow function syntax error in React
- Redux form weird arrow function syntax
- Correct syntax to apply a method within render () using arrow function
- curly braces in es6 arrow function for each
- ES6 Arrow Function Compile Error
- react map es6 arrow function doesn't work
- Formatting a function within componentDidMount() - syntax question
- React - arrow function syntax
- How to pass parameter from child to parent using function in react with es6 syntax
- Syntax error on async arrow function
More Query from same tag
- How to authenticate CloudKit JS in react JS or React-Redux JS
- React - how to use the lifecycle methods
- Context API using useContext in React Native is showing a TypeError
- AXIOS Async/Await How to best write the code?
- React props being mutated before setState called (react-beautiful-dnd)
- How do I render this map?
- React - dynamic use of country-flag-icons library
- AG Grid rowDrag Rows being dragged takes up full width of screen
- Formik and Yup : TypeError: Cannot read property 'object' of undefined
- Warning after signup and login in ReactJS
- how to pass function variable from one file to another in react
- I am not able to store the returned value of a javaScript function (of Geocoding) in a variable
- How to render empty element to dom in React?
- How to create a basic Tooltip in React where you don't actually wrap the anchor element in another DOM element?
- How to update multiple states using Immutability Helper | React JS
- how to render react component to another web app
- npm package.json config variables used for version numbers
- UseReducer change state
- Implementing Twilio Api call from a CURL example to js returns status code of 200 but does not seem to update data
- Understanding component prop inheritence in React
- How to handle click on child element
- TypeError: Cannot read property 'map' of undefined React Hooks
- Issue with image download using node
- How to implement reusable component input in vue 3?
- Navbar conditional rendering
- TypeError: this.state.webOrders.map is not a function
- React Redux deleting item from array at specific index
- Passing input value to my graphql mutation - react/react-apollo
- Should I use a React Component if it always renders null, or just use a function?
- Why does React rerender when the state is set to the same value the first time via an onClick event on DOM, but not react-native?