Skip to content

Instantly share code, notes, and snippets.

View jamesblashill's full-sized avatar

James Blashill jamesblashill

View GitHub Profile
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 October 3, 2019 20:42
Hooks vs class component
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]);