Deano Deano - 2 months ago 14
React JSX Question

react-native style tag "can't find variable" error

I'm trying to style a text element in my component, and when attempting to apply style tag "textStyle", I'm getting the following error:

enter image description here

Here is my code:

import React from 'react';
import { Text } from 'react-native';

// Create a Component

const Header = () => {
return <Text style={textStyle}>Albums!</Text>;
};

const styles = {
textStyle: {
fontSize: 30
}
};
export default Header;

Answer

You are missing styles, see following block of code:

const Header = () => {
  return <Text style={styles.textStyle}>Albums!</Text>;
};