This is my code:
const dfEventQuery = async (event: string) => {
const {
data: { result }
} = await axios.post("/api/df_event_query", { event, userId });
for (let msg of result.fulfillmentMessages) {
const botSay: MessageDataType = { speaks: "bot", msg };
setMessages(oldMessages => [...oldMessages, botSay]);
}
};
const resolveInXSeconds = (x: number) =>
new Promise(res => {
setTimeout(() => {
res(x);
}, x * 1000);
});
useEffect(() => {
dfEventQuery("Welcome");
if (inputRef.current) inputRef.current.focus();
const sendShopWelcome = async () => {
await resolveInXSeconds(1);
dfEventQuery("WELCOME_SHOP");
setShopWelcomeSent(true);
setShowChatbot(true);
};
if (window.location.pathname === "/shop" && !shopWelcomeSent) {
sendShopWelcome();
}
history.listen(() => {
if (history.location.pathname === "/shop" && !shopWelcomeSent) {
sendShopWelcome();
}
});
}, [shopWelcomeSent, history]);
I have this error:
React Hook useEffect has a missing dependency: 'dfEventQuery'. Either include it or remove the dependency array
but when i add it on the array: [shopWelcomeSent, history, dfEventQuery] I get this error:
The 'dfEventQuery' function makes the dependencies of useEffect Hook (at line 201) change on every render. To fix this, wrap the 'dfEventQuery' definition into its own useCallback() Hook
I've been stuck with it for hours and just can't wrap my head why this don't work?
dfEventQuerycoming from?