You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current behavior of the usePrevious hook is to always return null as the previous value. But in some cases, it makes sense to have a different default value. For example for a table's data we don't want to pass null as the value instead we want to pass an empty array:
functionMyTable({data, loading}){constpreviousData=usePrevious(data);// This throws an exception when the component gets rendered with loading true:consttable=useReactTable({data: loading ? previousData: data});return(// ...);}
Instead, I would like to be able to set an initial value for the hook:
functionMyTable({data, loading}){constpreviousData=usePrevious(data,[]);// No error this time since previousData is [] at first render when loading is true:consttable=useReactTable({data: loading ? previousData: data});return(// ...);}
The text was updated successfully, but these errors were encountered:
The current behavior of the
usePrevious
hook is to always returnnull
as the previous value. But in some cases, it makes sense to have a different default value. For example for a table's data we don't want to pass null as the value instead we want to pass an empty array:Instead, I would like to be able to set an initial value for the hook:
The text was updated successfully, but these errors were encountered: