Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I'm new to REACT, I want to hide/display a row if I click on VisibilityIcon/VisibilityiconOff. The icon will be put for each row on the Show column in my table.

Here what I have done but when I click on the icon Display VisibilityIcon all the table is hidden instead of hiding only the row and display the VisibilityOffIcon:

What I have tried:

JavaScript
    export default function MenuDetail() {
    const { menuId } = useParams();
    const { match } = JsonRules;
    const matchData = match.find((el) => el._id_menu === menuId)?._ids ?? [];
    const [show, setShow] = useState(true);

    const data = useMemo(
        () => [
            //some headers ....
            {
                Header: 'Show',
                accessor: (row) => <button onClick={() => setShow(!show)}>
                    {show ?
                        <VisibilityIcon/>
                        :
                        <VisibilityOffIcon/>
                    }
                </button>
            }
        ],[]
    );
    ...
    return (
        {
            show?
                <Table
                    data = { matchData }
                    columns = { data }
                    initialState = { initialState }
                    withCellBorder
                    withRowBorder
                    withSorting
                    withPagination
                />
            : null
        }
    );
}


I try to browse the Table to get each row with map but not working. I believe my syntaxe is wrong...
Posted
Updated 15-Apr-22 10:34am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900