Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFocusEffect render twice #671

Open
mrrs878 opened this issue Jun 19, 2023 · 2 comments
Open

useFocusEffect render twice #671

mrrs878 opened this issue Jun 19, 2023 · 2 comments

Comments

@mrrs878
Copy link

mrrs878 commented Jun 19, 2023

Which package manager are you using? (Yarn is recommended)

yarn

Summary

useFocusEffect render twice when entry page

This doesn't happen if i use useFocusEffect impoted from '@react-navigation/native'

Minimal reproducible example

import { useFocusEffect } from 'expo-router';

export default () => {

    // log 2 times
    console.log('render');

    useFocusEffect(useCallback(() => {
        //
    }, []));

    return (
        <Text>hello</Text>
    );
};
@Mickeygogo
Copy link

航总牛逼

@LiZhequ
Copy link

LiZhequ commented Aug 8, 2024

看起来是里面的useOptionalNavigation 导致重新渲染

const FocusEffect: FC<{ effect: EffectCallback }> = ({ effect }) => {
  useFocusEffect(effect)
  return null
}

给改成组件使用,可以避免其他组件渲染

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants