score:3
Accepted answer
this would certainly work:
axischange(event) {
event.persist();
this.setstate(prevstate => ({
selectedtemplatedata: {
...prevstate.selectedtemplatedata,
axislables: [...event.target.value.split(',')]
}
}))
}
if there is no comma, the value will be preserved. if there is a comma, you can split the values and spread them into the new array.
score:1
here you'll find other examples, but a simple way to do it is the following:
axischange(event) {
event.persist();
const e = event && event.target && event.target.value;
const values = e && e.split(',').length > 1
? e.split(',')
: e;
this.setstate(prevstate => ({
selectedtemplatedata: {
...prevstate.selectedtemplatedata,
axislables: [ values[0], values[1], values[n] ]
}
}))
}
Source: stackoverflow.com
Related Query
- React JS: Check for comma within input value
- Check react input form for decimals and change value
- Check if input has the same value React
- react input field for text, after rerender the component, the input still hold the old value
- show default value in select input with backgroundcoulr different for each : react js
- React TypeScript: Set initial value for input with useRef
- using state value in state data for apex charts within react app
- React check children input field value
- React doesn't change input value with looping array for initial value
- How to check If the value of an input is number or string in react js?
- how to set the default value for the input from a db in React
- In React how to make input check box ticked based on object value
- How to input an existing value into an input field in React for an edit form
- Check for a value onClick react
- React setState and then check for the value
- queryselector none when I ask for an input value in react
- React js - check for element value in array of Options
- Is it optional to use value for input in Controlled component in React
- Why can't I change my input value in React even with the onChange listener
- Why can't I change my input value in React even with the onChange listener
- React + Redux - Input onChange is very slow when typing in when the input have a value from the state
- React - clearing an input value after form submit
- React Input Element : Value vs Default Value
- React - "'value' prop on 'input' should not be null" for some input but not others
- How can I test a change handler for a file-type input in React using Jest/Enzyme?
- Updating a React Input text field with the value on onBlur event
- Set React Input Field Value from JavaScript or JQuery
- How to check for broken images in React JS
- React autoFocus sets cursor to beginning of input value
- react bootstrap readonly input within formcontrol
More Query from same tag
- Reactjs default Form validation with event.preventDefault()
- Dynamically render a sequence of divs
- Choosing the correct way to call function in stateful component
- Zoom in and out on image in React.js
- TypeError: queryClient.defaultQueryObserverOptions is not a function
- net::ERR_CONNECTION_REFUSED to cube.dv
- React ES6 component inheritance: working, but not recommended?
- How to get the hostname of a url in react js
- How to render JSON in React
- Update the Old and New Value in Redux
- React Router's HashRouter redirects to <base> tag url
- How to implement file Download button in Next.js? (window is not defined)
- Redux isn't mapping state to props in a way I can use the object
- How to setState for array immediately?
- ReactErrorUtils.invokeGuardedCallback in React fires event repeatedly in IE browser
- Make table cell textOverflow dynamic as per width
- How do I limit my react-redux app to only make API request when required data is not available?
- Trouble accessing nested array data using React useState
- 415 (Unsupported Media Type) with REST Post request
- How can I add Vanilla JS to my react app to create Image Modal pop-ups?
- setState doesnt seem to update the state
- Ordering data inside .map
- Change a single product quantity using state (react)
- toggle state for multiple elements in Reactjs
- Best way to handle complex State in React
- How to access an element of a nested array without using map in React?
- location.state fail with gatsby build
- react - can you mutate modify this.props.children to dynamically (programatically) add children components
- How can i add class to a image element in quill image Handler?
- Fetching data from API failed