Frontend interview quick reference lookup
|
Add Script
|
<script src="foo.com/react.js" crossorigin />
|
|
Add targeting div
|
<div id="react" />
|
|
Get root Dom
|
root = document.getElementById("root");
|
|
Bootstrap React
|
ReactDOM.render(<App />, rootElement);
|
|
const [state, setState] = useState(initialState);
|
|
useEffect(() => { ...logic, return cleanup}, [deps]);
|
|
useMemo(() => computeExpensiveValue(a, b), [a, b]);
|
|
Context
ThemeContext = React.createContext(themes.light); <ThemeContext.Provider value={themes.dark}> theme = useContext(ThemeContext); background: theme.background |
|
useRef
const inputEl = useRef(null); <input ref={inputEl} /> inputEl.current.focus(); |
useFetch = (param) => {
const [state, setState] = useState([]);
useEffect(() => {
async function fetchData() {
const response = await fetch('url');
const data = await response.json();
setState((prev) => prev.concat(data.results));
}
fetchData();
}, [param]);
return { state };
};
|
Insert at Start
|
unshift()
|
|
Insert at End
|
push()
|
|
Insert at Location
|
splice(start, 0, item2, itemN)
|
|
Remove First
|
shift()
|
|
Remove Last
|
pop()
|
|
Remove at Location
|
splice(start, deleteCount)
|
|
Get parts
|
slice(start, end)
|
|
DFS
|
getNodes(root)
[...getNodes(root.left), getNodes(root.right)] |
|
BFS
|
while(queue.length)
for(queue.length) node = queue.shift() queue.push(node.left/right) |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.