-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed states to refs in Tile.tsx to prevent rerenders
- Loading branch information
Showing
4 changed files
with
83 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createContext, useContext, useRef, MutableRefObject, ReactNode } from 'react'; | ||
import { ColoredGroup } from './Tile'; | ||
|
||
type SelectedTileRefType = MutableRefObject<ColoredGroup | undefined> | undefined; | ||
|
||
const SelectedTileRef = createContext<SelectedTileRefType>(undefined); | ||
|
||
export const useSelectedTile = () => { | ||
return useContext(SelectedTileRef); | ||
}; | ||
|
||
interface SelectedTileProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const SelectedTileProvider = ({ children }: SelectedTileProviderProps) => { | ||
const globalRef = useRef<any>(null); | ||
|
||
return <SelectedTileRef.Provider value={globalRef}>{children}</SelectedTileRef.Provider>; | ||
}; |
This file contains 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
This file contains 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