Possible to update state via functionalUpdate by passing in updater manually?
I have a state like this.
Trying to update this state within the pagination onChange. I do not have access to the
// Model
pageTokens: Record<number, string | undefined>;
// Setter
table.setPageToken = (page, token) => {
table.setState((old) => {
return {
...old,
pageTokens: {
...old.pageTokens,
[page]: token,
},
};
});
};
// Model
pageTokens: Record<number, string | undefined>;
// Setter
table.setPageToken = (page, token) => {
table.setState((old) => {
return {
...old,
pageTokens: {
...old.pageTokens,
[page]: token,
},
};
});
};
table
instance here.
onPaginationChange: (updater) => {
const currentPagination = {
pageIndex: search.page - 1, // Set to 0-based index
pageSize: search.pageSize,
};
const newPagination = functionalUpdate(updater, currentPagination);
const newPage = newPagination.pageIndex + 1; // Set back to 1-based index;
const newPageSize = newPagination.pageSize;
functionalUpdate(
(old) => {
return {
...old,
pageTokens: {
...old.pageTokens,
[newPage]: search.token,
},
};
},
{ pageTokens: { [newPage]: search.token } },
);
onPaginationChange: (updater) => {
const currentPagination = {
pageIndex: search.page - 1, // Set to 0-based index
pageSize: search.pageSize,
};
const newPagination = functionalUpdate(updater, currentPagination);
const newPage = newPagination.pageIndex + 1; // Set back to 1-based index;
const newPageSize = newPagination.pageSize;
functionalUpdate(
(old) => {
return {
...old,
pageTokens: {
...old.pageTokens,
[newPage]: search.token,
},
};
},
{ pageTokens: { [newPage]: search.token } },
);
0 Replies