I have calendar, If I click on day, I would like to make copy of this value and store it to Array, and if I click on another day, I would like to get current day copy and add it to array with prev day value. User can select multiple days. How can I do this? I am trying this way
const [dates, setDates] = useState([])
console.log(dates)
const handleClick = (e) => {
e.preventDefault()
const selectedDya = e.target.textContent
console.log(selectedDya)
setDates((prev) => ({...prev}, selectedDya))
}
<section className='week'>
{data[0][0].map((item, i) => (
<span key={i}
onClick={handleClick}
className={'cell'}>
{item}
</span>
))}
</section>
3
Answers
In your click handler function, do this:
This adds the newly selected date to your previous array.
To store the selected dates in an array and accumulate the values as new dates are clicked, you need to make a few modifications
There are a few modifications you can make to achieve your desired functionality. Here’s an updated version of your code that should work: