How to update state.hiddenColumn=[]?
See original GitHub issueHi, I have an external function to trigger state.hiddenColumn provided in react table v7 using useEffect. The table and hidden columns is not rerender after I pass new props hiddenColumn. How to update state.hiddenColumn array properly. I have read the documentation, but not any example real code include.
Piece of my code
component 1
export default function Project(props: any) {
const [value, setValue] = React.useState<Array<string>>([]);
const hide1 = () => {
const hiddenColumn= ["status", "timeline"];
setValue(hiddenColumn);
};
return (
<div className="view-project-wrapper">
<button onClick={hide1}>test 1</button>
<Table columns={columns}
data={data} hiddenColumns={value} />
</div>
);
}
component 2
function Table({ columns, data, hiddenColumns = [] }) {
console.log("table");
console.log(hiddenColumns);
// Use the state and functions returned from useTable to build your UI
const { getTableProps, headerGroups, rows, prepareRow } = useTable(
{
columns,
data,
initialState: {
hiddenColumns: hiddenColumns
}
},
useFlexLayout,
// useBlockLayout,
useResizeColumns,
useSticky
);
React.useEffect(() => {
console.log("useEffect");
});
// Render the UI for your table
return (.....rest)
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
How to update state.hiddenColumn=[]? · Issue #1880 - GitHub
Hi, I have an external function to trigger state.hiddenColumn provided in react table v7 using useEffect. The table and hidden columns is ...
Read more >Has column show property stopped working in latest react ...
Instead of setting show in the column, set the initialState.hiddenColumns , here you can convert your existing show into the initial hidden ......
Read more >React Table Tutorial - 16 - Column Hiding - YouTube
React Table Tutorial - 16 - Column Hiding ; Courses - https://learn.codevolution.dev/ ; Support UPI - https://support.codevolution.dev/ ;
Read more >React Table Column Visibility Example | TanStack Table Docs
An example showing how to implement Column Visibility in React Table.
Read more >Hidden Columns - Grid - Kendo UI for Angular - Telerik
You can configure the hidden state of the columns by: Using the built-in configuration options of the Grid. Using the Angular structural directives....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well that’s one way, but it looks like you’re trying to fit a React lifecycle method into a React effect hook. Using the following piece of code would achieve the same in the way it’s meant to be used.
Thanks for reply, I don’t know how to use columnvisibility. But, I have found the solution using setHiddenColumns()