7. THE PROBLEMS OF HOC
THE PROBLEMS OF HOC
Change Component name
8. THE PROBLEMS OF HOC
THE PROBLEMS OF HOC
Change Component name
Add component hierarchy
9. THE PROBLEMS OF HOC
THE PROBLEMS OF HOC
Change Component name
Add component hierarchy
More maintenance cost(component will spit to
component itself and wrapperComponent)
10.
11. RENDERPROPS(FACC - FUNCTION AS CHILD COMPONENT)
RENDERPROPS(FACC - FUNCTION AS CHILD COMPONENT)
const MyContext = React.createContext(defaultValue);
<MyContext.Provider value={/* some value */}>
<MyContext.Consumer>
{value => /* render something based on the context value */}
</MyContext.Consumer>
12. THE PROBLEM OF FACC
THE PROBLEM OF FACC
“There are only two hard things in
Computer Science: cache invalidation
and naming things.”
– Popularly attributed to Phil Karlton
16. THE PROBLEMS OF CLASS
THE PROBLEMS OF CLASS
Is "this" really necessary?
17. THE PROBLEMS OF CLASS
THE PROBLEMS OF CLASS
Is "this" really necessary?
The instance function must bind "this"
18. THE PROBLEMS OF CLASS
THE PROBLEMS OF CLASS
Is "this" really necessary?
The instance function must bind "this"
Too much outside logic in component lifecycle:
didMount/willRecieveProps/didupdate
19. THE PROBLEMS OF CLASS
THE PROBLEMS OF CLASS
Is "this" really necessary?
The instance function must bind "this"
Too much outside logic in component lifecycle:
didMount/willRecieveProps/didupdate
Class is not friendly to code optimization
36. THE RULES OF HOOKS
THE RULES OF HOOKS
Hooks can only be called at the top level of a React
function component.
cannot be called inside a function method.
cannot be called in condition block.
cannot be called in loop block.
Hooks can be called inside custom react hooks.
Separate component dependencies and
component UI*
37. SEPARATE COMPONENT DEPENDENCIES AND COMPONENT
SEPARATE COMPONENT DEPENDENCIES AND COMPONENT
UI
UI
const CreateMarkTaskModal: FunctionComponent<Props> = props => {
const { onSubmit, visible, ...rest } = props;
const [datasetList, updatedAtasetList] = useState<StateList>([]
const [initialized, updateInitialized] = useState<boolean>(fals
const [tagsetData, updateTagsetData] = useState<StateList>([]);
const [versionList, updateVersionList] = useState<StateList>([]
const [isFetchingTagset, fetchTagset] = usePromisifyObservable<u
() => listAllTagsets(),
data => updateTagsetData(data.map(({ name }) => name)),
);
const [isFetchingDatalist, fetchDataList] = usePromisifyObservab
() => listDataset(),
response => updatedAtasetList(response.map(({ name }) => name
);
38. FROM CLASS COMPONENT TO FUNCTION
FROM CLASS COMPONENT TO FUNCTION
COMPONENT
COMPONENT
Constructor
useState
getDerivedStateFromProps
shouldComponentUpdate
useCallback
useMemo
Probably Don't Need It
45. RECAP
RECAP
Hooks is function.
Hooks split components into multiple Code
Blocks, allowing smaller-grained logic to reuse and
improve performance.
"This" in the React Class component is useless in
most scenarios.
Most of the logic of React Class components can
be simulated by Hooks.
The rules of Hooks.
1. Hooks can only be called top level of React
function components.
46. 2. Hooks can be called by custom hooks.
3. Separate component dependencies and
component UI.*