I have a candlestick chart for a crypto and it has different timeframe for 1 minute, 30, minute, and so on. I currently have
const [data, setData] = useState[]
useEffect(() => {
const fetchPrice = async () => {
const { data } = await axios.get(`/api/apii?slug=${poolName[0].pool_id}&timeframe=`${1h}``); // default is 1h
const btcusd = data.data.results.map(
(d) => {
return {
open: d.open,
close: d.close,
low: d.low,
high: d.high,
time: toDateStamp(d.datetime),
};
}
);
setData(btcusd)
};
fetchPrice()
}, []);
The above is the initial state whenever a user visits which he or she will be shown a 1-hour chart data. So there is this onClick button which will fetch and set new state according to he chosen timeframe. It works if i setData for one timeframe but then if I set another timeframe, how do I separate them?