Cheatography
https://cheatography.com
Frontend interview quick reference lookup
React Setup
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); |
React Hooks
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(); |
async useEffect
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 };
};
|
|
|
JS Arrays
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) |
Algos
DFS |
getNodes(root) [...getNodes(root.left), getNodes(root.right)] |
BFS |
while(queue.length) for(queue.length) node = queue.shift() queue.push(node.left/right) |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets