score:1
Accepted answer
you are mapping the selecteditem
array for every element in the item
array. this means for any element in the array that some condition matches and both the input and label are rendered.
if i understand the code and your expected behavior i think you should conditionally render a single input or label based on if the selecteditem
array includes an element matching by id.
example:
<div classname="app">
{items.map((item) => (
<div classname="issue">
<input type="checkbox" onchange={(e) => handleselect(e, item)} />
<label>{item.name}</label>
{selecteditem.length ? (
selecteditem.some((singleitem) => singleitem.id === item.id) ? (
<input type="number" />
) : (
<label>not selected</label>
)
) : (
"list is empty"
)}
</div>
))}
</div>
Source: stackoverflow.com
Related Query
- How to compare objects of two different arrays in javascript
- how to compare two specific elements from two different Arrays in JavaScript
- How to compare two different arrays with common properties
- How to compare array objects present in two different React states
- How can I compare two arrays of objects and add new key to an objects in the second array
- Compare Two different arrays and update array of objects with useState in React
- How to compare two array of objects in javascript and update the value?
- How can we compare objects by value stored inside two arrays of objects in JavaScript?
- compare two arrays of Objects in JavaScript and if true save new items to MongoDB
- How to compare two big arrays of objects on identity
- How to compare object properties between different objects in different arrays
- How do I compare two arrays of objects to see if they have the same ids and then return another value from the matching object?
- React useEffect() : Most efficient way to compare if two arrays of objects are equal
- JavaScript how to map over two arrays one object
- How to render two different arrays data into a single array of objects?
- How do I merge two Javascript Objects into one?
- How do I extract two arrays from a JSON with nested objects
- Compare two arrays and filter them javascript
- Javascript how to see if two objects with array of string contain the same value
- How do I compare two different API requests to get and display duplicate values in Reactjs?
- A lookup function to match the same IDs in two different arrays of objects and inserting key/value pairs into one of the array of objects
- How to compare two arrays and remove unmatched record
- how can I search in 2 different arrays of objects if there is an id withn both when doing a map?
- How to compare if, 2 separate Objects/Array have one same element and concat 2 objects into one array, if there is matching element? Javascript
- How would you compare two arrays and filter between the two arrays?
- Merge two arrays of different objects into one array of objects combined from the first two
- How to iterate a table of information with two different arrays made into one
- How to compare two typed objects (with interface) in React?
- How to merge two arrays of objects in ReactJS?
- How to update contents of objects inside arrays javascript
More Query from same tag
- Formik and FieldArray Mapping with Typescript
- Best ways to update state array object using React Hooks?
- Making a slide down menu
- State nulls out inside render function in React
- Insert an array into state using useState hook in React
- Hook won't get properly mocked Jest
- Receiving ERROR #98123 after gatsby develop
- Updating redux state based on service response
- ReactJS - watch access token expiration
- Extend child component props into wrapper component
- Enzyme test nested component's method
- Cannot read property 'setState' of undefined - progress bar
- Get state right after setState()
- Express/mssql login form throws "ReferenceError:"" is not defined"
- React-tsx-Download Multiple image file in Zip format
- Jest - testing a component that uses react-router
- Stop interval function when changing site
- Upgrading storybook from 6.3.7 to 6.4.22 shows spinner and no stories in react/typescript
- Which syntax is more typical to React, if any (version 16)?
- goBack() button doesn't work. HashRouter React
- Many Internal Server Errors
- How can I replicate the Netflix jawbone animation?
- How can I get the values of all sibling input checkboxes in a child component?
- Naming conventions for manual mocks in Jest test runner
- How to display fields from FieldArray in a different component (one component up) with redux-form
- Promise return from catch with Axios and final-form
- React Js with Visual studio 2017 with Typescript
- Implement the scroll func in React without using DOM selector
- How can I add compoent to another component in React?
- how to change bootstrap class with changing values in react js?