Javascript 反应本族语-我如何摆脱警告;无法从函数体内部更新组件…”;
我已经在类似的Javascript 反应本族语-我如何摆脱警告;无法从函数体内部更新组件…”;,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我已经在类似的Stackoverflow上搜索了所有类似的问题,但我有一个不同的问题,因为这个问题要求从child组件调用parent函数 以下是我尝试过的代码: export default ()=>{ const Drawer = createDrawerNavigator(); const [progress, setProgress] = React.useState(new Reanimated.Value(0)); const scale = Reanimated.
Stackoverflow
上搜索了所有类似的问题,但我有一个不同的问题,因为这个问题要求从child
组件调用parent
函数
以下是我尝试过的代码:
export default ()=>{
const Drawer = createDrawerNavigator();
const [progress, setProgress] = React.useState(new Reanimated.Value(0));
const scale = Reanimated.interpolate(progress, {
inputRange: [0, 1],
outputRange: [1, 0.8],
});
const animatedStyle = { borderRadius, transform: [{ scale }] };
return(
<NavigationContainer>
<View style={{flex:1, backgroundColor:'black'}}>
<Drawer.Navigator
{...anotherProps}
drawerContent={props=>{
setProgress(props.progress); //Here the Warning appears
return <CustomDrawer {...props}/>
}}
>
<Drawer.Screen name="Drawer">
{StackNavigatorScreen}
</Drawer.Screen>
</Drawer.Navigator>
</View>
</NavigationContainer>
)
}
导出默认值()=>{
const Drawer=createDrawerNavigator();
const[progress,setProgress]=React.useState(新的复活的.Value(0));
常量比例=复活。插值(进度{
输入范围:[0,1],
输出范围:[1,0.8],
});
const animatedStyle={borderRadius,transform:[{scale}]};
返回(
{
setProgress(props.progress);//此时会出现警告
返回
}}
>
{StackNavigatorScreen}
)
}
任何人都可以帮助我如何使用我当前的代码使此警告消失
无法从其他组件的函数体内部更新组件
将setStatte更改为const progress=new Animated.Value(0)并将抽屉内内容放入progress.setValue(props.progress)@AshwithSaldanha该方法允许动画延迟将setStatte更改为const progress=new Animated.Value(0)并将抽屉内内容放入progress.setValue(props.progress)@AshwithSaldanha该方法允许动画延迟