Skip to content

Instantly share code, notes, and snippets.

View przemwo's full-sized avatar

Przemek Wolnik przemwo

View GitHub Profile
@przemwo
przemwo / App.js
Created June 26, 2019 18:47
useReducer mimicks class's setState function
import React, { useReducer, useEffect } from 'react';
const reducer = (state, updatedProperty) => ({
...state,
...updatedProperty,
});
const initState = {
name: 'John',
@przemwo
przemwo / App.js
Last active June 26, 2019 17:18
React.memo with useCallback hook
import React, { useState, useCallback } from 'react';
export function App() {
const [counter, setCounter] = useState(0);
// const increment = (n) => {
// setCounter(c => c + n);
// };
const increment = useCallback((n) => {
@przemwo
przemwo / readme.md
Created May 16, 2019 20:34
Visual comparison between Function component with useEffect hook and Class component

Function component with useEffect vs Class component

Do you work with React for some time and try to wrap your head around hooks? Here you can check what's the difference between Class component with lifecycle methods and Function component with useEffect.

image