I'm using useContext in a component page, and it correctly gets datas through useContext in a type of a property.
colorContex.js
import { createContext, useEffect, useState, useContext } from 'react';
// create context object
export const ColorContext = createContext({});
export const ProductsProvider = (props) => {
const [data, setData] = useState(null);
useEffect(() => {
async function fetchAPI() {
const res = await fetch(url);
const posts = await res.json();
setData(posts);
}
fetchAPI();
}, []);
return <ColorContext.Provider value={data}>{props.children}</ColorContext.Provider>;
};
headerDefault.tsx
const colors = useContext(ColorContext);
console.log(colors);
// the data shows up correctly in console log
const colorData = colors.response;
// the error message( the property doesn't exist type {}. )
the data is correct and a type of property. How can I get property datas?