I'm trying to pass setChart
to ChartType
and i want to update setChart
in ChartType
component.
so I tried to use array with null, but for some reason, I get this error : TypeError: setChart is not a function
so How can I update setChart
to change the chart with a different div ??
ChartTypePage
const ChartTypePage = ({ changeLayout }) => {
const [chart, setChart] = useState([
null,
null,
null,
null,
null,
null,
null,
null,
]);
const layout = [
<Side id="first" key="a" onClick={chartItself}>
<ChartType visible={visible[0]} setChart={setChart[0]} />
{chart[0]}
</Side>,
<Side id="second" key="b" onClick={chartItself}>
<ChartType visible={visible[1]} setChart={setChart[1]} />
{chart[1]}
</Side>,
<Side id="third" key="c" onClick={chartItself}>
<ChartType visible={visible[2]} setChart={setChart[2]} />
{chart[2]}
</Side>,
ChartType
const ChartType = ({ visible, setChart }) => {
const chartType = [
<Bar
key="p"
data={chartData}
options={{ responsive: true, maintainAspectRatio: false }}
/>,
<Line
key="p"
data={chartData}
options={{ responsive: true, maintainAspectRatio: false }}
/>,
<Radar
key="p"
data={chartData}
options={{ responsive: true, maintainAspectRatio: false }}
/>]
return (
<TypeBox visible={visible}>
<div>
<div onClick={() => setChart(chartType[0])}>
<h3>Line</h3>
</div>
<div onClick={() => setChart(chartType[1])}>
<h3>Bar</h3>
</div>
<div onClick={() => setChart(chartType[2])}>
<h3>Radar</h3>
</div>
<div onClick={() => setChart(chartType[3])}>
<h3>Pie</h3>
</div>
</div>
</TypeBox>
);
};
export default ChartType;