Last active
October 5, 2021 04:21
-
-
Save notsidney/2fa3f77a4c068322528aa897a7ae75d5 to your computer and use it in GitHub Desktop.
How to useRef to Fix React Performance Issues — Gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SideDrawerRef } from 'SideDrawer' | |
export function ProjectContextProvider({ children }) { | |
const sideDrawerRef = useRef<SideDrawerRef>(); | |
return ( | |
<ProjectContext.Provider value={{ sideDrawerRef }}> | |
{children} | |
</ProjectContext.Provider> | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type SideDrawerRef = { | |
cell: SelectedCell; | |
setCell: React.Dispatch<React.SetStateAction<SelectedCell>>; | |
open: boolean; | |
setOpen: React.Dispatch<React.SetStateAction<boolean>>; | |
}; | |
export default function SideDrawer() { | |
const classes = useStyles(); | |
const { tableState, dataGridRef, sideDrawerRef } = useProjectContext(); | |
const [cell, setCell] = useState<SelectedCell>(null); | |
const [open, setOpen] = useState(false); | |
sideDrawerRef.current = { cell, setCell, open, setOpen }; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment