.push () nie aktualizuje zmiennej
const datas=[]; //move your `datas` to the global scope
export default function App() {
const [data,setData]= useState([]);
const [activity, setActivity]= useState([])
const [name, setName] = useState("")
useEffect(()=>{
// handlePress()
}, [setData, setName])
const rand= Math.floor(Math.random(1,5)*4)+1
const events=["Event A","Event B","Event C","Event D","Event E"]
const handlePress=(day)=>{
setData(day); //`data` will be changed later
setName(`${events[rand]}`)
datas.push(day); //push `day` directly instead of data
console.log(datas);
}
return (
<div className="App">
<Calendar
onDayPress={day => {
{handlePress(day)}
}}
/>
</div>
);
}
SAMER SAEID