score:1
Accepted answer
i'd advice against it, because such a one-liner makes the code quite unreadable, in my opinion.
anyway, here it is...
{array.map((v,i) => {
<input onchange={
(e)=>setarray(
[...array.slice(0, i), e.target.value, ...array.slice(i+1)]
)}
/>
})}
given the array [1,2,3,4,5]
and i=2
you will have:
...array.slice(0, i)
→[1,2]
e.target.value
→ the new value...array.slice(i+1)
→[4,5]
Source: stackoverflow.com
Related Query
- Updating the state inside map function using react hooks using spread operator
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to manipulate the DOM inside of map function using onChange event on one of the checkboxes with react hooks
- Why is the state not updating inside this react Hooks component?
- How do I correctly add data from multiple endpoints called inside useEffect to the state object using React Hooks and Context API?
- How to dynamically and conditionally render select options inside of a map function using React Hooks
- Updating component state by Listening to socket events inside react hooks or handling them inside middleware? what are the downsides of each one?
- React Hooks: Instantiating state hooks on validation Error: Invalid hook call. Hooks can only be called inside of the body of a function component
- React onSubmit wait for async IIFE inside the function to update state with hooks
- Using spread operator to avoid mutating state in React function
- Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component when using Create React App and Formik
- React Lifting State: Updating state in the child using setState function from parent
- React Hooks Error: Hooks can only be called inside the body of a function component
- Updating the array object in React state using immutability helper
- state inside useEffect refers the initial state always with React Hooks
- Using react hooks inside render prop function
- How to get the changed state after an async action, using React functional hooks
- How to loop inside map function using jsx format React JS
- React: How to add onChange functionality inside of Function component using React Hooks? Need onClick event from a checkbox to influence input state
- React Using useState/Hooks In HOC Causes Error "Hooks can only be called inside of the body of a function component"
- React + Antd + Rollup Component Library "Error: Invalid hook call. Hooks can only be called inside of the body of a function component"
- React Hooks can only be called inside the body of a function component
- Component not updating on Map (dictionary) state change using hooks
- React 17.0.1: Invalid hook call. Hooks can only be called inside of the body of a function component
- Can't see state inside method helper function using hooks
- Receiving error - Hooks can only be called inside of the body of a function component when implementing React Spring basic example
- Invalid hook call. Hooks can only be called inside of the body of a function component using react-apollo
- Will using the React props spread operator significantly slow-up my application?
- My state is not updating using React Hooks
- React Hooks Mobx: invalid hook call. Hooks can only be called inside of the body of a function component
More Query from same tag
- How "npm start" works in create-react-apps
- Missing dependencies in package.json while creating React App
- How to add infinite scroll in react redux app
- How do I make this React Core UI Tab Pane component work?
- SetState with react hook and redux after async call to axios API
- React fetch('http://localhost:3000/profile/:id')
- Combining Multiple Reducers
- Why does my simple React form using hooks not work?
- Conditionally add attribute that requires an array
- Access String array in Json
- How do I change the ripple background color on Button?
- PropTypes validation fails in functional component
- Missing semicolon linting error with typescript
- Webpack-dev-server not bundling even after showing bundle valid message
- supportedChain is deprecated, please pass networks instead
- Facing ant-design form validation issue on production
- Scroll to element in React based on "getElementsByName" function
- axios get request for real-time data
- Setting context state with vs without constructor
- What am I doing wrong when trying to set a cookie using Express
- React: Props destructuring and memory usage
- Symlinking react modules with npm link for local development gives error
- Only show Popup one time with React (local storage)
- Keeping track of selected div in grid of divs with React state
- How to avoid setState() inside render() when state depends on render
- How to query full size image using gatsby-image?
- Warning: validateDOMNesting(...): <form> cannot appear as a descendant of <form>
- TypeScript how to write this more pragmatic?
- Conditional rendering in React + Gatsby Static Query + GraphQL
- How can I update my nested component's state using mount()?