[英]How not to reexplicit instance components properties in generic components?
In react, I implement generic components like this :在反应中,我实现了这样的通用组件:
export function CustomTextInput(props) {
return (
<TextInput
placeholder={props.placeholder}
onChangeText={props.onChangeText}
style={{margin:20}}
/>
)
}
And them I use them like this :我像这样使用它们:
<CustomTextInput
placeholder="My placeholder"
onChangeText={secretCode => setSecretCode(secretCode)}
/>
Is there a way not to have to re-explicit each property in the generic components ?有没有办法不必重新显式泛型组件中的每个属性? For example, by defining generic components like that :
例如,通过定义这样的通用组件:
export function CustomTextInput(props) {
return (
<TextInput
props={props}
style={{margin:20}}
/>
)
}
... while still keeping the same implementation for component instances. ...同时仍然为组件实例保持相同的实现。
You can transfer props using the spread syntax
as follows.您可以使用
spread syntax
传输道具,如下所示。
export function CustomTextInput(props) {
return (
<TextInput
{...props}
style={{margin:20}}
/>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.