How to trigger a user event in a client component without causing the server component rebuild?
Unanswered
Pteromalid wasp posted this in #help-forum
Pteromalid waspOP
I have the following structure
In the
I currently use search param to make the
<ClientComponent1 />
<SeverComponent>
<ClientComponent2 />
</SeverComponent>In the
ClientComponent1, there is a search bar that filter the data in the ClientComponent2. The SeverComponent is used for fetching data from the sever and push it to the useQuery. I currently use search param to make the
ClientComponent2 receive the ClientComponent1 search terms but it will make the SeverComponent fetch the data from api again.7 Replies
@Pteromalid wasp I have the following structure
html
<ClientComponent1 />
<SeverComponent>
<ClientComponent2 />
</SeverComponent>
In the `ClientComponent1`, there is a search bar that filter the data in the `ClientComponent2`. The `SeverComponent` is used for fetching data from the sever and push it to the useQuery.
I currently use search param to make the `ClientComponent2` receive the `ClientComponent1` search terms but it will make the `SeverComponent` fetch the data from api again.
you can use window.history.pushState/window.history.replaceState to update url queries without reloading the server components https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api
@joulev you can use window.history.pushState/window.history.replaceState to update url queries without reloading the server components <https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api>
Pteromalid waspOP
that exactly what i want. Thanks
btw, if im not going to use search query, is there any other way to achieve the same thing?
@Pteromalid wasp btw, if im not going to use search query, is there any other way to achieve the same thing?
<Context>
<ClientComponent1 />
<ServerComponent>
<ClientComponent2 />
</ServerComponent>
</Context>both client components read from and write to the context
Pteromalid waspOP
if i have multiple structure like this in one page, which means multiple search bar, do u recommend using context or search query?
it depends on the purpose of those search bars, but 99% of the time i prefer search bars
* 99% of the time I prefer search queries, sorry my brain farted