JavaScript/react/useSelector:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
无编辑摘要
Kangkk​(留言 | 贡献)
第24行: 第24行:
     scrollIntoView => scrollIntoView.type === 'group'
     scrollIntoView => scrollIntoView.type === 'group'
   ));</syntaxhighlight>
   ));</syntaxhighlight>
== 示例 ==
<syntaxhighlight lang="javascript">
...
  const [activeGroupId, setActiveGroupId] = useState(0);
  const scrollIntoView = useSelector(createSelector(
    state => state.canvas.scrollIntoView,
    _ => _.type === 'group' && _
  ), shallowEqual);
  useEffect(() => {
    if (!scrollIntoView) return;
    setActiveGroupId(scrollIntoView.id);
  }, [scrollIntoView]);</syntaxhighlight>