我正在使用useEffect钩子,在某些情况下,我不需要返回任何东西。如何处理这种情况最好?
// fooRef is a reference to a textfield (belonging to the same component). Sometimes the fooRef is not there,because of redirections) that's why I need to check if it exists
useEffect(() => fooRef.current && fooRef.current.focus() , [fooRef])
当按照这种方式使用时,React将会抛出以下错误信息: “effect函数除了用于清理的函数之外,不应该返回任何东西。你返回了null。如果你的effect不需要清理,返回undefined(或什么也不返回)会更好。” 那么最好的选择是返回undefined还是一个空函数呢?