#Making the data value changeable

2 messages · Page 1 of 1 (latest)

turbid hound
#

Hello, I have a question about making the data I get back changeable, namely what happens is that I have a useQuery that gives me back an id from the server, but in my queryFn the id is a query parameter, which is supposed to be changed whenever I select a different user in the UI through a Dropdown component.

const { isLoading: isLoadingUsers, data: users } = useQuery(
    ["users"],
    () => getUsers(),
    {
      select: (data) => 
        data
          ?.filter((user) => user.email === session.user.email)
          .map((user) => ({ user_id: user.id, org_id: user.org_id })),
    }
  );

This is how I get the id as well as another id, which is irrelevant. However I do not know how I can have that id as the first id on page load, and then whenever I choose a different user from a Dropdown, for that id to change. It made a bit of sense to me to do it with useState to put the id I get back as the initial state, and then update it whenever I pick something from the Dropdown, but that doesn't work for me

turbid hound
#

Also, the first useQuery I wrote above's data value is used for another useQuery, the value is inserted in the dependency array, however, currently, that value doesn't change, it's always the first value I get through the first useQuery