So here's the scenario: I'm working on a Next.js project where I have a context for modals. In this context, I store modal details in an array called modalBase. Additionally, I fetch data from another context (toolsContext) to pass it to components. The issue arises when I console log the data in this context - it shows up correctly. However, after passing the data to components, it becomes undefined. I'm quite puzzled by this.
const [data, setData] = useState();
const [modals, setModals] = useState([]);
const router = useRouter();
const query = router.query;
const { collectionData } = useContext(toolsContext);
useEffect(() => {
const getData = async () => {
const ss = await collectionData(query.taskId);
setData(ss);
};
getData();
}, []);
// ======= Modal details
const modalsBase = [
{
name: "collectCreator",
openStatus: false,
content: <CollectionForm />,
},
{
name: "taskItemCreator",
openStatus: false,
content: <TaskItemForm data={data} />,
},
{
name: "taskCreator",
openStatus: false,
content: <TasksForm data={data} />,
},
{
name: "collectionEdit",
openStatus: false,
content: <CollectionEditForm data={data} />,
},
{
name: "taskItemEdit",
openStatus: false,
content: <TaskItemEditForm />,
},
{
name: "tasksEdit",
openStatus: false,
content: <TasksEditForm />,
},
];
My hunch is that the issue stems from trying to pass data to components within the array.