ios - React Native Stateless component saying undefined -


i'm trying create component using react native so:

export class indicatoroverlay extends component {   render() {     return (       <view>         <text>text</text>       </view>     );   } }; 

the above works, when try make stateless so...

export default ({ text = 'text' }) => {   return (     <view>       <text>{text}</text>     </view>   ); }; 

i following error:

element type invalid: expected string (for built-in components) or class/function (for composite components) got: undefined. forgot export component file it's defined in.

i'm sure i'm missing basic, can't see it. use similar stateless component in react web app , it's fine.

using react 16.0.0-alpha.6 , react-native 0.43.2, , seeing error in iphone simulator.

hope can :)

this because first example named export, while second 1 default 1 therefore way need import them different.

assuming import module this:

import { indicatoroverlay } 'indicatoroverlay'; 

you have 2 options. either:

1) change way import module (since stateless component default export now):

import indicatoroverlay 'indicatoroverlay'; 

2) keep import intact, refactor stateless component this:

export const indicatoroverlay = ({text = 'text'}) => {   return (     <view>       <text>{text}</text>     </view>   ); }; 

you can make more dry btw:

export const indicatoroverlay = ({ text = 'text' }) => (   <view>     <text>{text}</text>   </view> ); 

you can read more imports , exports on mdn:


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -