I'm making a visitor call system with React Query.
I have a kind of call (button) and I want to call the api only when it is pressed. However, when the component is rendered, it keeps calling the api.
- How not to call the component when it is rendered
- How to call api only when button is pressed
What should I do?
//App.jsx
const query = useQuery('resData', getEmployData('datas'), {
enabled: false
});
const callBtn = () => {
query.refetch()
}
return (
<ul>
<li onClick ={callBtn}>Post</li>
<li>Food</li>
<li>Other</li>
</ul>
)
this is api function
const getEmployData = async(callKind) => {
const {data} = await axios.get(`${baseUrl}/welcome?callKind=${callKind}`);
return data
}