I am using react navigation 5. I want to redirect with Token. But the function works twice and returns null in the first. What is the reason and solution?
export default function Router(){
    const [token, setToken] = useState(null);
    useEffect(() => {
        getToken();
    }, []);
    const getToken = async () => {
        const token = await AsyncStorage.getItem('token');
        setToken(token);
    };
    console.log("token:") //console
    console.log(token)
    return (
        <NavigationContainer>
            <AppStack.Navigator>
                {
                    token=== null ?
                    //..
                }
            </AppStack.Navigator>
        </NavigationContainer>
    );
}
//output
token:
null
token:
eyJhbGci..
Two rounds at the beginning and showing null in the first round prevents the program from running.
 
     
    