I have a shopping cart which is stored as an object array, and I am currently trying to make a post request by passing the array into it. But alas I am running into problems.
When trying to set the data it just shows that it is empty. I am hoping once I can fill it I can just send it as an array and unpack it once Laravel has it.
I (we) got it across, and its catching in the query, don't remember it ever doing that before when just working with laravel, but progress is progress! I think setting the state was not needed come to think of it. There is no need for a re rendering, but grabbing the data in query troubles me.
public function store(Request $request)
{
dd($request->query);
}
const handleCheckout = (e) => {
e.preventDefault();
if (total === 0) {
setModalState(true)
return;
}
else if (total > 0) {
let itemsArr = Object.values(itemsCount)
post(route('checkout.store', [itemsArr]));
}
}
@Sinnbeck I didn't bother passing it to data. I need to learn about the render cycle of React because I keep running into a problem where the var is not filling, my guess is that the render cycle hasn't finished and will update again on the next one, but by this time it is too late because I am already gone on the post.
@Randy_Johnson Think of it as you start from the top of the component and see what the state of each prop + useState variable is. The page is rendered top to bottom. If you change any data using setFoo() or similar, or a prop change from a parent, it will rerender, but as the variables are the at the top, they wont be set below where they are set
const [foo, setFoo] = useState('apple');
setFoo('banana')
console.log(foo); //foo is still apple, until the next render cycle
@Sinnbeck Hey, so I fixed it, I just stuck it in useEffect. Now I should really focus on learning good structuring of an application. Thanks again Sinn!