score:2
Accepted answer
addmistake(event){
this.setstate((prevstate) => ({mistake: prevstate.mistake.concat([this.state.value]))
});
console.log("mistake is "+ this.state.mistake.length + " and value is "+ this.state.value);
}
in render method
render(){
return(
<div>
<input value={this.state.value} type='text' onchange={this.handlechange} />
<button onclick={this.addmistake}> add mistake </button>
<div>
{this.state.mistake.length && this.state.mistake.map(item =><p> {item} </p>) }
</div>
<div>{this.state.value}</div>
</div>
);
}
this.state.mistake.length
checks if we have anything in the array.
score:0
following syntax worked for me! thank you @omar and @hamms
addmistake(event){
this.setstate({mistake: this.state.mistake.concat([this.state.value])
});
console.log("mistake is "+ this.state.mistake.length + " and value is "+ this.state.value);
}
Source: stackoverflow.com
Related Query
- How to append new value in existing array in React State?
- How to push new value to array state in react
- How to add a new key value to react js state array?
- How to update specific value when the state is an array of objects - React
- How to add a value to an array inside a React state
- How can I update singular value of Array in React State
- how do i update state in react for updating the value of an object inside an array using array.map function
- Reactjs: How to update value in state array with react hooks?
- How to append to state array in React hooks?
- How to push a new value into the current array using the react hooks?
- How to push new value in array useState in react
- how to store textarea new line value into array with react and send it to node js variable with post request
- React - How to use the current state value as a variable so i can set as a index inside an array
- How to create new state for every value in state array
- how to go through react state variable array and determine if it has one true value
- How to add a new value to existing object in array
- How can I store previous values instead of storing the value in array of objects in react state
- How to update an existing value in state array without mutation?
- How to update React State in an array of objects? Update if id exists, otherwise append
- How do I take an array of objects from state and push a specific value of the objects into a new array
- How to instantly update react state after replacing the value from array
- How to add a new textfield on button click and add integer value of that input field to an array in react
- React - How can i add new value to an array and display this array in alert window?
- How to update value of a key in object in an array with the new value in React useState in TypeScript
- How to add new Properties to File object in React with state value dynamically
- how to append object array to current state in react functional component
- How to add new object into existing state using react and redux saga
- how can i add setinterval function inside React new array state
- How to sort json array by date value dd/mm/yyyy to update React state
- How to push Value in an array exist inside in an object of state in react
More Query from same tag
- React.js fetch method on my api is not working?
- useQuery : not getting data
- How to change background of aws amplify/cognito login/signup screen
- Required prop `onClick` was not specified // Cannot read property 'bind'
- SetAll from CreateEntityAdapter do not set the state with react redux toolkit
- I need a nested route in react router V5
- How to track changes of a referenced element with React?
- React : Focus on Froala Editor (On External Event)
- Cannot set property 'styles' of undefined in next js during add less support
- React-Apollo Query refetch causes children to unmount
- Cannot delete product item from Firebase
- Re-render List after deleting item in child component
- Problem With Adding Custom Styling to ReactJS Google Map
- Remove html attribute in production build
- Why is the product search filter not working in the Thinking in React tutorial
- How do I avoid the warning: chunk styles [mini-css-extract-plugin] Conflicting order in GatsbyJS?
- React Router v6 useRouteMatch equivalent
- RealTime chart in recharts
- How to access map function state and use in external function
- Default Values from API in MUI Text field
- React Navbar is not showing
- radio tabIndex to navigate using tab doesn't work in react
- Yup Validation causing errors
- I Need better way To Hide SideNavigator from some routes and another not?
- Change Text Color When a Word is Clicked
- Get embed tweet widget with react.js
- How to let qt webengine call react compontent function
- Fetch runs double with old and updated value
- data.json() is not a function (React)
- Deploying nextjs app on Heroku - error status H20