1

I have this piece of code

  componentWillMount() {
    return fetch("http://10.0.3.2:8080/all", {
        method: "GET",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json"
        }
    })
        .then(response => response.json())
        .then(responseData => {
            this.ds = new ListView.DataSource({
                rowHasChanged: (r1, r2) => r1 !== r2
            });
            this.setState({
                dataSource: this.ds.cloneWithRows(responseData)
            });
        })
        .catch(error => {
            console.log("error : " + error);
        });
};

It brings me the data from my api, i already test it with console.log(this.state.dataSource) and the result was console.log result

But when i add the code

<ListView
    dataSource={this.state.dataSource}
    renderRow={(rowData, navi) => this.renderEvent(rowData, this.props.nav)}
/>

I receive this error Error

1 Answer 1

1

Is this issue fixed by adding a simple constructor to your main component? I'd imagine you are getting this issue because you haven't received the data yet at the time of your initial render. Something like

class Test extends Component{
    constructor(props){
        super(props);

        this.state = {
            dataSource = [];
        }
   }

So when you have your ListView , atleast it will have something to pull from initially.

Hope this helps, but if not, have a look at this article , explains this concept further in depth.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.