-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
34 lines (26 loc) · 839 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// @noflow
/* eslint-disable no-console */
import React, {useState, useEffect} from 'react';
export const logEvent = (name) => (event) => {
console.log(`[${name}]`, event);
};
export const Result = ({children}) => <div className="result">{children}</div>;
export const ErrorResult = ({children}) => (
<div className="error">{children}</div>
);
// Demo hook to dynamically change font size based on window size.
export const useDynamicFontSize = () => {
const [fontSize, setFontSize] = useState(
window.innerWidth < 450 ? '14px' : '18px'
);
useEffect(() => {
const onResize = () => {
setFontSize(window.innerWidth < 450 ? '14px' : '18px');
};
window.addEventListener('resize', onResize);
return () => {
window.removeEventListener('resize', onResize);
};
}, []);
return fontSize;
};