useSSE icon indicating copy to clipboard operation
useSSE copied to clipboard

does support dependency query ?

Open huyansheng3 opened this issue 4 years ago • 1 comments

<A>
   <B></B>
</A>

A :

const [dataA, error] = useSSE(() => {
    return fetch("https://myapi.example.com").then((res) => res.json());
  }, []);

B:

const [dataB, error] = useSSE(() => {
    return fetch("https://myapi.example.com", {params: dataA.id}).then((res) => res.json());
  }, []);

query need dataA , how handle this condition ?

huyansheng3 avatar Nov 29 '21 10:11 huyansheng3

pass your dataA to second useSSE in array, its dependency array so your second call should be:

const [dataB, error] = useSSE(() => {
    return fetch("https://myapi.example.com", {params: dataA.id}).then((res) => res.json());
  }, [dataA]);

nekiro avatar Dec 16 '21 17:12 nekiro