I am trying to use the flowing code in my component, I keep getting the error:
Unexpected token (9:8), which if the return statement.
Can anyone help?
export class Flexible extends React.Component {
const { style, children, ...rest } = this.props;
return <View {...rest} style={styles.flexible}>{children}</View>;
}
You're creating a class, which only accepts properties and functions.
It looks like you are trying to create the render
method - let's do that then:
export class Flexible extends React.Component {
render() {
const { style, children, ...rest } = this.props;
return <View {...rest} style={styles.flexible}>{children}</View>;
}
}
If you don't need state or any of the life cycle functions (componentWillMount
etc), you can get away with just creating a functional component:
export const Flexible = (props) => {
const { style, children, ...rest } = props;
return <View {...rest} style={styles.flexible}>{children}</View>;
};
It's understandable to get the two mixed up - they do look kind of similar to the untrained eye :)
Hope this fixed your issue!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments