I would like to create a new instance of a component and then use a function within that component to add add a new object. Nothing works for me. Here is my code:
The component that holds the list and the function to add new eventCard
function EventDay (props) {
const [ events, setEvents ] = useState([{eventName: "first event"}]);
function addEvent(eventCard) {
setEvents( prevEvents => [...prevEvents, eventCard]);
}
return console.log(events);
}
export default EventDay;
the component that wants to access the addEvent function
import EventDay from "./EventDay"
function App() {
const eventDay = new EventDay();
eventDay.addEvent({eventName: "New Event"});
}
I get an error addEvent is not a function. I tried to export it but I can't since it's a function within a function. How can I achieve the above?