我試圖為我的應用程式創建一個自定義按鈕,以便以后使用,它看起來像這樣的
const BUTTON_SHAPE: ViewStyle = {
borderRadius: 30,
alignItems: 'center',
justifyContent: 'center',
};
export 介面 AppButtonProps {
style? ViewStyle。
child? Element | React.ReactNode。
}
const AppButton = (props: AppButtonProps) => {
const {style, child} = props;
return (
<TouchableOpacity style={[style, BUTTON_SHAPE]}> {child}</TouchableOpacity>
);
};
export default AppButton;
但是,當我在App中使用這個時:
<ViewContainer style={{alignItems: 'center', justifyContent: 'center'}}>
<AppButton>>。
<Text>/span>Hello</Text>
</AppButton>/span>
<AppText>Login</AppText>
</ViewContainer>
它顯示錯誤:
Type '{ children: in common with type 'IntrinsicAttributes & AppButtonProps' 沒有屬性 in common with type 'IntrinsicAttributes & AppButtonProps'
如何解決這個問題?
我怎樣才能解決這個問題,我做錯了什么?
uj5u.com熱心網友回復:
要在React中傳遞子元素,你應該使用特殊的children屬性
簡單地將你的AppButton child道具升級為children
const BUTTON_SHAPE: ViewStyle = {
borderRadius: 30,
alignItems: 'center',
justifyContent: 'center',
};
export 介面 AppButtonProps {
style? ViewStyle。
兒女?Element | React.ReactNode。
}
const AppButton = (props: AppButtonProps) => {
const {style, children} = props;
return (
<TouchableOpacity style={[style, BUTTON_SHAPE]}> {children}</TouchableOpacity>
);
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/309146.html
標籤:
上一篇:如何在databricks的scala代碼中添加日志?
下一篇:從一個物件中獲取一個值的反應本地

