Answer the question
In order to leave comments, you need to log in
How to pass the children component to another component?
I have a Button component in react-native app
const Button = ({children, callback, ...props}) => {
return (
<MainButton {...props} onPress={callback}>
<Text>
{props.children}
</Text>
</MainButton>
)
}
<Button
callback={() => setStatusQrCode(false)}
color={color_white}
background={color_blue}
weight={600}>
{<Text>Продолжить</Text>}
</Button>
Answer the question
In order to leave comments, you need to log in
const Button = ({ children, callback, ...props }) => {
return <MainButton {...props} onPress={callback}>{children}</MainButton>;
};
So children contains all the components that you have registered inside the tag. Roughly speaking, the component tree.
If you want to pass all the components nested in it to MainButton -> Text in the button component, then you need to figure out not props.children there, but directly the children argument
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question