25-reactjs-interview-projects icon indicating copy to clipboard operation
25-reactjs-interview-projects copied to clipboard

load-more-data Line 23 needs to be replaced with setProducts([...products, ...result.products]);

Open Rope-a-dope opened this issue 8 months ago • 1 comments

because when you pass a parameter to the call back function and you spread it then render result.products , its like rendering the same result.products twice , and that is why you see the warning below of two identical Id or why you see items rendered twice ... but when we set it like this setProducts(() => [...products, ...result.products]); it means that we will spread the prev products from the state which in the initial state is set to [ ] so it means if there is no products then there will be no previos products to be spread and no error will appear

setProducts((prevData) => [...prevData, ...result.products]);

to

setProducts([...products, ...result.products]);

Rope-a-dope avatar May 30 '24 01:05 Rope-a-dope