score:1
You can use something like this...
{Steps.map((lista, index) => (
<details className='collapse'>
<summary className='title'>{lista.title}</summary>
<div className='description'>
{lista.desc}
</div>
</details>
))}
details and summary are HTML tags for collapse.
score:0
if you are trying to change the state by the value in the state please pass a function to setState as first argument like this:
this.setState((state, props) => ({
show: !state.show
}));
score:0
You need to create a state for each one of your list elements. Then you can change them individually.
First I'd add an id
to each one of the Steps
item.
const Steps = [
{
id: 1,
title: '1. Download Tattoo master app (dropdown)',
desc: 'Download the application in App Store and you acan find the wizard in any location around the world. '
},
{
id: 2,
title: '2. Enter your location',
desc: 'Download the application in App Store and you acan find the wizard in any location around the world.'
},
{
id: 3,
title: '3. Find your tattoo master',
desc: 'Download the application in App Store and you acan find the wizard in any location around the world.'
}
]
Second I'd change my show
state to an Object. That way I can store the id of each item and them tell if it is true
or false
.
this.state = {
show: {}
}
And finally I'd change the function to change each item state based on its id
.
toggleListItem(itemId) {
this.setState((prevState) => ({
...prevState,
show: {
...prevState.show,
[itemId]: !prevState.show[itemId]
}
}))
}
<div key={lista.id} onClick={() => this.toggleListItem(lista.id)} className="dropdown"> ... </div>
You can see it working here: https://codesandbox.io/s/priceless-browser-uxdr5
You can have a quick explanation about using prevState
here:
What is prevState in ReactJS?
Source: stackoverflow.com
Related Query
- How to show only one active item at a time with react and material ui
- My React list item components don't render one at a time
- Show/Hide elements of a list on click, one list item a time (react app)
- REACT JS How to show one component and hide the others on click
- React Spring - Animate list - one item in list at a time
- Material-UI Left Drawer in App Bar won't close on overlay click or menu item click in React
- Show hide multiple elements with react
- React - show hide two elements without flickering on page load
- React re-renders entire list when one item is changed
- how to run my node application and react app in the same time with one command?
- show - hide component with hook function works only one time
- React Js custom accordion, open one item at the time
- react change the class of list item on click
- loop through an array and show single item at a time with dynamic time duration like setTimeout or SetInterval in react js
- how to handle click only one <li> item in react
- How to set click listener on list item in material ui in react js
- React using LocalStorage to show or hide elements
- How can I check only one check box at a time instead of all in a list of checkboxes in React
- React click on item to show details
- How to Hide and show HTML based on a cookie existing or not in a React App
- How to refresh the table data when one of the item has its valid till date and time has expired in React Js
- Only show Popup one time with React (local storage)
- Custom reusable react component to show or Hide child elements based on flag
- Click on React list of elements and store it as a value in another list
- React - Show an array value at a time and change with the click
- Toggle one list item at a time with React/TS functional components
- How to change React chartjs-2 legend click functionality to hide all except the one clicked?
- How can I make only one list item expand when a button is clicked in React (no hooks)?
- get value of list item with click event in React
- React Router hide App content when click other pages link
More Query from same tag
- React useEffect Warning: Maximum update depth exceeded. Is there a way around this?
- How to customize button css in react-admin
- ANT Design Push Pull Confusion
- How to fix a this react filter?
- How h1 tag take attributes to make it responsive - ReactJS
- unable to install material-ui/core in reactjs project?
- ReactJS randomly Unexpected token '<'
- How to overwrite fetch using Javascript?
- React Bootstrap error: 'AccordionCollapseProps' is not exported from './AccordionCollapse'
- How to fetch api from the function which pushes each api in array?
- How to upload file to backend in react
- Adding a class to a certain element in ReactJS
- Reactstrap Tooltip throws target could not be identified in the dom error with dynamic IDs
- TypeError this.getData is not a function
- Restyling parent elements the React way
- ReactJS state depending on another state
- Default Route With React Router 4
- Passing react-table row data to react-modal
- Error when testing react components with jest and css-modules
- How to copy an object in the array to another array based on a specific value
- Returning the base URL in React
- Incrementing through an array index onClick In React
- why my reducer is slow to storage the result?
- Redux state getting reset after page change
- Extending styles with styled-components not working
- Bracket notation while adding imported objects
- ReactJs change time video html5
- How to call children method from parent's constructor?
- How to use different routes for a same page in Next.js?
- React Native Ios Error - ENOENT: no such file or directory, uv_cwd (null))