React Native trying to use same array globally

  Kiến thức lập trình

I am trying to learn React Native and am wondering if there is a way to store an array, say in a constant file or something, and reuse it in different components. States will be one, as an example. I want to create an array of States for a dropdown select component (I am using react-native-element-dropdown for that) and use it in several different components. The array would be like:

const states = [
    { label: 'Alabama', value: 'AL' },
    { label: 'Alaska', value: 'AK' },
    { label: 'Arizona', value: 'AZ' },
    { label: 'Arkansas', value: 'AR' },
    { label: 'California', value: 'CA' },
    { label: 'Colorado', value: 'CO' },
    { label: 'Connecticut', value: 'CT' },
    { label: 'Delaware', value: 'DE' },
];

I’m not even sure there is a way to do this, but everything I have tried so far has errored out with too many renders errors. I have to ask before I start copying and pasting these long arrays 🙂

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT