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
describe('ViewState', () => { | |
test('default state', () => { | |
const viewState = new ViewState(); | |
expect(viewState.showSomething).toBe(false); | |
}); | |
test('toggleShowingSomething()', () => { | |
const viewState = new ViewState(); | |
viewState.toggleShowingSomething(); | |
expect(viewState.showSomething).toBe(true); |
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
export const ScrollIntoView: React.FC<IProps> = memo( | |
withRouter<IWithRouterProps, React.FC<IWithRouterProps>>( | |
({ id, className, children, top, location }) => { | |
const ref = useRef<HTMLDivElement>(null); | |
useEffect(() => { | |
if (location.hash === `#${id}` && ref.current) { | |
ref.current.scrollIntoView(); | |
} | |
}, [location]); |