Dhiemas Ganisha
Dhiemas Ganisha

Reputation: 223

View style is not working in React Native

Im new in react native, before in my code using const Main = () => { ..}

but when i change to export default class Main extends React.Component { ..} , problems arise like style in View not working but the error ',' expected in style

Screnshoot :

enter image description here

im using new version of react native

Upvotes: 0

Views: 164

Answers (1)

dragon
dragon

Reputation: 1274

You are missing the render() method where the return() method should be.

Ex:

export default class LotsOfStyles extends Component {
  render() {
    return (
      <View>
        <Text style={styles.red}>just red</Text>
        <Text style={styles.bigBlue}>just bigBlue</Text>
        <Text style={[styles.bigBlue, styles.red]}>bigBlue, then red</Text>
        <Text style={[styles.red, styles.bigBlue]}>red, then bigBlue</Text>
      </View>
    );
  }
}

from react native docs

Upvotes: 2

Related Questions