code_novice_1234
code_novice_1234

Reputation: 87

React native keep getting Text string must be rendered within <Text>

Can someone tell me why I keep getting this error:

Text string must be rendered within a component

I've taken out portions of the API key.

Here is my code:-

componentDidMount() {
    fetch(
        `https://api.nomics.com/v1/currencies/ticker?key=11300ce692510973c&ids&interval=5m,30d&convert=GBP&per-page=100&page=1`
      ).then((response) => response.json())
      .then((data) => {
          const ndata = data;
          const test = data.map((element) => element);
          this.setState({ new: test }); })}
  render() {
  const test = this.state.new.map((e)=>{return(<SvgUri width="10%" height="10%" source={{uri:e.logo_url}}/>)})
    return (
<View>{test}</View>
    )
  }     
  }

Upvotes: 0

Views: 99

Answers (2)

Diwakar Prasad
Diwakar Prasad

Reputation: 76

try doing this like this.

{ `test.map(logo => logo)` }

Because here test

const test = this.state.new.map((e)=>{return(<SvgUri width="10%" height="10%" source={{uri:e.logo_url}}/>)});

returns a array of svg

Upvotes: 0

Aseer KT Miqdad
Aseer KT Miqdad

Reputation: 153

You have to wrap test in a Text component if it ended up having a type string. In react native, you can only put text within a Text component

<View>
  <Text>{test}</Text>
<View>

Upvotes: 1

Related Questions