I want to add one element to the new array but the bug notification confused me and not work.If user click the color pickerinput
and inputtitle
and click the Add Color
button,one new card will show on the case.This is my expectation.
import ColorCards from "./ColorCards";
import React, { useState } from "react";
import data from "./initialState.json";
import { v4 as uuidv4 } from "uuid";
export default function CardsafterEvents({ title, color }) {
const [colors, setColors] = useState(data.colors);
const onRemove = (id) => {
const newcolors = colors.filter((color) => color.id !== id);
setColors(newcolors);
};
const AddColor = (id, title, color, timestamp) => {
const newcolors = [
...colors,
{
id: uuidv4(),
title: title,
color: color,
timestamp: new Date()
}
];
setColors(newcolors);
};
return (
<>
<ColorCards
dataColors={colors}
handleDelete={onRemove}
title={title}
color={color}
HandleColor={AddColor}
/>
</>
);
}
full project link:https://codesandbox.io/s/material-demo-forked-62eh0?file=/CardsafterEvents.js:0-839