Hey there -
I'm trying to persist state of grid (dataState) through refreshes. This grid instance is processing data on the client-side. I have another grid instance performs data operations on the backend, and the req URL has search params.
My current approach is using URLSearchParams, but both this and react-router location return empty objects. I'm including the code, but I'm currently just trying access the url params.
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
console.log(params) // logs {}
const location = useLocation();
console.log('location', location)
Finally - is this the best way to approach this? I'd rather not add any libraries/frameworks and it doesn't make sense for us to store this info on the backend. So far I'm trying web APIs like above + localstorage. We do have react-router, but so far I haven't solved this issue.
Thank you!
const fetchAllJobsConfig = { baseURL: process.env.REACT_APP_API_URL, params: { dataState, }, headers, method: 'get', url, };
Hello, Abi,
The approach that you have selected seems to be the best one.
Alternatively, another possible take would be to use local storage in order to keep the grid state.
I made an example that showcases this approach here:
https://stackblitz.com/edit/react-grid-toggle-column-d8pvlr?file=index.js
I hope this helps.
Filip