How do I refresh data without reloading the page
I have a CRUD form working great, but with one last feature needed: refresh datasource. I have tried some recommendations using Route's reload and revalidation technique's but with no success. Here is a basic breakdown of what I have.
7 Replies
Server code:
Client code:
I want to know how to refresh the
projects
call with a refresh button on the page without needing to reload the page. Clicking to a different page and back also refreshes the data, of course.default
cache
duration is i think 5s
so to/from different page will only load after the cache is expired
for manual refreshing, revalidate()
should refresh everything
revalidate(getProjectsByUserId.key)
should refresh all createAsync
that calls getProjectsByUserId
for a particular user id revalidate(getProjectsByUserId.keyFor(10))
feel free to make a repro if it's not working for youIs this done on the server or client side? Would a refresh method look like this?
Server-Side:
Client-Side:
it should be done on the client
for server side reloading,
reload({ revalidate: ... })
under the hood, it will add the necessary info (just an http header) which the client will use it to reload
we probably should add some warnings for what to call, what not to callIf all you want to do is invalidate
getProjectsByUserId
, you can use revalidate
on the client. It'll refetch the server function automaticallydefinitely, doesn't make sense to make a server function just to reload
It worked!! I did this all on the client side with no server-side code needed!!
So within the client code that does the update
I also created a refresh function:
So when I update I call
Submit
and it updates the record, uses the returned value of ownerId
to invalidate and then refresh the data table successfully. It looks great.
And I added a refresh button to call refreshTableData
that invalidates the whole results and it refreshes the data perfectly without needing a page refresh!!!