Quantcast
Channel: React.js: Identifying different inputs with one onChange handler - Stack Overflow
Browsing all 14 articles
Browse latest View live

Answer by Shadab Ali for React.js: Identifying different inputs with one...

state objectconst [values, setValues] = useState({ email: "", password: "", });function that change stateconst handleChange = name => event => { setValues({ ...values, [name]: event.target.value...

View Article



Answer by Manu for React.js: Identifying different inputs with one onChange...

If anyone looking for Functional Component Example,import React, { useState } from "react";export default function Exapmle() {const [userState, setUserState] = useState({ firstName: "", lastName:...

View Article

Answer by Rajan for React.js: Identifying different inputs with one onChange...

The key of your state should be the same as the name of your input field. Then you can do this in the handleEvent method;this.setState({ [event.target.name]: event.target.value});

View Article

Answer by Georgi Peev for React.js: Identifying different inputs with one...

I will provide really simple solution to the problem.Suppose we have two inputs username and password,but we want our handle to be easy and generic ,so we can reuse it and don't write boilerplate...

View Article

Answer by inostia for React.js: Identifying different inputs with one...

You can also do it like this: ...constructor() { super(); this.state = { input1: 0, input2: 0 }; this.handleChange = this.handleChange.bind(this);}handleChange(input, value) { this.setState({ [input]:...

View Article


Answer by Javasamurai for React.js: Identifying different inputs with one...

You can track the value of each child input by creating a separate InputField component that manages the value of a single input. For example the InputField could be:var InputField =...

View Article

Answer by Christopher Davies for React.js: Identifying different inputs with...

The onChange event bubbles... So you can do something like this:// A sample formrender () {<form onChange={setField}><input name="input1" /><input name="input2" /></form>}And...

View Article

Answer by Albert Olivé Corbella for React.js: Identifying different inputs...

Hi have improved ssorallen answer. You don't need to bind function because you can access to the input without it.var Hello = React.createClass({ render: function() { var total = this.state.input1 +...

View Article


Answer by Janusz Kacalak for React.js: Identifying different inputs with one...

You can use a special React attribute called ref and then match the real DOM nodes in the onChange event using React's getDOMNode() function:handleClick: function(event) { if (event.target ===...

View Article


Answer by fiatjaf for React.js: Identifying different inputs with one...

You can use the .bind method to pre-build the parameters to the handleChange method.It would be something like: var Hello = React.createClass({ getInitialState: function() { return {input1:0,...

View Article

Answer by manu3569 for React.js: Identifying different inputs with one...

@Vigril Disgr4ceWhen it comes to multi field forms, it makes sense to use React's key feature: components.In my projects, I create TextField components, that take a value prop at minimum, and it takes...

View Article

Answer by Sebastien Lorber for React.js: Identifying different inputs with...

Deprecated solutionvalueLink/checkedLink are deprecated from core React, because it is confusing some users. This answer won't work if you use a recent version of React. But if you like it, you can...

View Article

Answer by Ross Allen for React.js: Identifying different inputs with one...

I suggest sticking to standard HTML attributes like name on input Elements to identify your inputs. Also, you don't need to keep "total" as a separate value in state because it is composable by adding...

View Article


React.js: Identifying different inputs with one onChange handler

Curious what the right way to approach this is:var Hello = React.createClass({getInitialState: function() { return {total: 0, input1:0, input2:0};},render: function() { return...

View Article
Browsing all 14 articles
Browse latest View live




Latest Images