Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

styled.View does not see props

This is literally one of my first components on react (and react-native too), so don’t swear if the error is elementary.

I want to make a flex component and I pass the child components and the direction="column" parameter into it, but I still have the flex-direction: row

What is wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

file 'flex.js':

const StyledFlex = styled.View`
  display: flex;
  flex-direction: ${props => props.direction || "row"};
`;


 const Flex = (props) => {
   return <StyledFlex> {props.children}</StyledFlex>
 }

----
 
usage:

export default function App() {
  return (
    <View>
      <StatusBar />
      <Header>
        <Flex direction="column">
          <ButtonStatistic />
          <ButtonAdd />
        </Flex>
      </Header>
    </View>
  )
}

Result:

enter image description here

As you can see, buttons are in row

>Solution :

You don’t pass the props to StyledFlex.

const Flex = (props) => {
  return <StyledFlex {...props}> 
    {props.children}</StyledFlex>
 }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading