JavaScript/react/useSelector:修订间差异
来自康健生活
无编辑摘要 |
|||
| 第6行: | 第6行: | ||
const { 'id': activeGroupId } = useSelector(state => state.canvas.scrollIntoView); | const { 'id': activeGroupId } = useSelector(state => state.canvas.scrollIntoView); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 浅层比较 == | == 浅层比较 == | ||
| 第16行: | 第14行: | ||
const { 'id': activeGroupId } = useSelector(state => state.canvas.scrollIntoView, shallowEqual); | const { 'id': activeGroupId } = useSelector(state => state.canvas.scrollIntoView, shallowEqual); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== reselect == | |||
<syntaxhighlight lang="javascript"> | |||
import { useSelector } from 'react-redux'; | |||
import { createSelector } from 'reselect'; | |||
... | |||
const { 'id': activeGroupId } = useSelector(createSelector( | |||
state => state.canvas.scrollIntoView, | |||
scrollIntoView => scrollIntoView.type === 'group' | |||
));</syntaxhighlight> | |||