-
Notifications
You must be signed in to change notification settings - Fork 13
usePersistentReactDataTableState added #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
usePersistentReactDataTableState added #87
Conversation
commit: |
|
|
||
| useEffect(() => { | ||
| // We can't set these values directly in the useReactDataTableState hook above, | ||
| // because the filter would be taken as default value also for the reset function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neotob so the idea here is to "rehydrate" the state on mount right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Michele-Masciave yes exactly, so a page reload will keep the previous data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect I see, LGTM then :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the useEffect is not that beautiful... if you see any other solution, please let me know 🙏
| setSorting, | ||
| } = useReactDataTableState<TData, TFilter>({ | ||
| initialColumnPinning: | ||
| getLocalStorageItem<useReactDataTableStateProps<TData, TFilter>["initialColumnPinning"]>(`${props.localStorageKey}_columnPinning`) ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neotob Can I ask why you try to read the localstorage here?
The useEffect is not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many times the query will be executed on the first render? 1 or 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manni497 I need to have the useEffect because the initial values didn;t decide between filter and afterSearchFilter... I added it now instead and was able to get ride of the useEffect.. I think this is better right?
It also loads directly correct ond the first query and will only do one call
|
|
||
| ### Added | ||
|
|
||
| - added the `usePersistentReactDataTableState` hook which saves it's own state into the local storage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the new prop
| /** | ||
| * the initial after search filter | ||
| */ | ||
| initialAfterSearchFilter?: ColumnFilterState<TFilter>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neotob Just curios of this use case, there could be really a case in which the initial column filters is different than the after search filter?
No description provided.