Skip to content

Instantly share code, notes, and snippets.

Avatar

James Blashill jamesblashill

View GitHub Profile
View ViewState.test.tsx
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);
@jamesblashill
jamesblashill / ScrollIntoView.tsx
Created Oct 3, 2019
Hooks vs class component
View ScrollIntoView.tsx
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]);