React and this.props.results.map is not a function









up vote
2
down vote

favorite












after tried to set a simple search in the logs show this:



error



everything seems very ok and standardized so a couple of searches i still have any idea why this error is happening.



i've tried with fetch and the same result



please, someone can elucidate, why this error is happening?



the code:



import React, Component from "react";
import axios from "axios";

import Suggestions from "./suggestions";

class Search extends Component
constructor(props)
super(props);

this.state =
term: "",
error: false,
results:
;


onChange(e)
this.setState(
term: e.target.value ,

() =>
axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data ))
.catch(() => this.setState( error: true ));

);


render()
return (
<div id="searchbox">
<div>
<form>
<input
ref=input =>
this.search = input;

value=this.state.term
onChange=this.onChange.bind(this)
type="text"
placeholder="Search..."
/>

<button type="submit">
<i className="search icon" />
</button>
<Suggestions results=this.state.results />
</form>
</div>
</div>
);



export default Search;


the suggestion



import React from "react";

const Suggestions = props =>
const resultList = props.results.map(r => <li key=r.id>r.title</li>);
return <ul>resultList</ul>;
;

export default Suggestions;


response



response










share|improve this question



















  • 1




    What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
    – Tholle
    Nov 9 at 21:59











  • @Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
    – lula
    Nov 9 at 22:07






  • 1




    change .then(res => this.setState( results: res.data )) to res.data.posts
    – SakoBu
    Nov 9 at 22:11










  • @SakoBu thank you very much. :)
    – lula
    Nov 9 at 22:14














up vote
2
down vote

favorite












after tried to set a simple search in the logs show this:



error



everything seems very ok and standardized so a couple of searches i still have any idea why this error is happening.



i've tried with fetch and the same result



please, someone can elucidate, why this error is happening?



the code:



import React, Component from "react";
import axios from "axios";

import Suggestions from "./suggestions";

class Search extends Component
constructor(props)
super(props);

this.state =
term: "",
error: false,
results:
;


onChange(e)
this.setState(
term: e.target.value ,

() =>
axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data ))
.catch(() => this.setState( error: true ));

);


render()
return (
<div id="searchbox">
<div>
<form>
<input
ref=input =>
this.search = input;

value=this.state.term
onChange=this.onChange.bind(this)
type="text"
placeholder="Search..."
/>

<button type="submit">
<i className="search icon" />
</button>
<Suggestions results=this.state.results />
</form>
</div>
</div>
);



export default Search;


the suggestion



import React from "react";

const Suggestions = props =>
const resultList = props.results.map(r => <li key=r.id>r.title</li>);
return <ul>resultList</ul>;
;

export default Suggestions;


response



response










share|improve this question



















  • 1




    What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
    – Tholle
    Nov 9 at 21:59











  • @Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
    – lula
    Nov 9 at 22:07






  • 1




    change .then(res => this.setState( results: res.data )) to res.data.posts
    – SakoBu
    Nov 9 at 22:11










  • @SakoBu thank you very much. :)
    – lula
    Nov 9 at 22:14












up vote
2
down vote

favorite









up vote
2
down vote

favorite











after tried to set a simple search in the logs show this:



error



everything seems very ok and standardized so a couple of searches i still have any idea why this error is happening.



i've tried with fetch and the same result



please, someone can elucidate, why this error is happening?



the code:



import React, Component from "react";
import axios from "axios";

import Suggestions from "./suggestions";

class Search extends Component
constructor(props)
super(props);

this.state =
term: "",
error: false,
results:
;


onChange(e)
this.setState(
term: e.target.value ,

() =>
axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data ))
.catch(() => this.setState( error: true ));

);


render()
return (
<div id="searchbox">
<div>
<form>
<input
ref=input =>
this.search = input;

value=this.state.term
onChange=this.onChange.bind(this)
type="text"
placeholder="Search..."
/>

<button type="submit">
<i className="search icon" />
</button>
<Suggestions results=this.state.results />
</form>
</div>
</div>
);



export default Search;


the suggestion



import React from "react";

const Suggestions = props =>
const resultList = props.results.map(r => <li key=r.id>r.title</li>);
return <ul>resultList</ul>;
;

export default Suggestions;


response



response










share|improve this question















after tried to set a simple search in the logs show this:



error



everything seems very ok and standardized so a couple of searches i still have any idea why this error is happening.



i've tried with fetch and the same result



please, someone can elucidate, why this error is happening?



the code:



import React, Component from "react";
import axios from "axios";

import Suggestions from "./suggestions";

class Search extends Component
constructor(props)
super(props);

this.state =
term: "",
error: false,
results:
;


onChange(e)
this.setState(
term: e.target.value ,

() =>
axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data ))
.catch(() => this.setState( error: true ));

);


render()
return (
<div id="searchbox">
<div>
<form>
<input
ref=input =>
this.search = input;

value=this.state.term
onChange=this.onChange.bind(this)
type="text"
placeholder="Search..."
/>

<button type="submit">
<i className="search icon" />
</button>
<Suggestions results=this.state.results />
</form>
</div>
</div>
);



export default Search;


the suggestion



import React from "react";

const Suggestions = props =>
const resultList = props.results.map(r => <li key=r.id>r.title</li>);
return <ul>resultList</ul>;
;

export default Suggestions;


response



response







javascript reactjs axios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 22:08

























asked Nov 9 at 21:57









lula

16510




16510







  • 1




    What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
    – Tholle
    Nov 9 at 21:59











  • @Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
    – lula
    Nov 9 at 22:07






  • 1




    change .then(res => this.setState( results: res.data )) to res.data.posts
    – SakoBu
    Nov 9 at 22:11










  • @SakoBu thank you very much. :)
    – lula
    Nov 9 at 22:14












  • 1




    What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
    – Tholle
    Nov 9 at 21:59











  • @Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
    – lula
    Nov 9 at 22:07






  • 1




    change .then(res => this.setState( results: res.data )) to res.data.posts
    – SakoBu
    Nov 9 at 22:11










  • @SakoBu thank you very much. :)
    – lula
    Nov 9 at 22:14







1




1




What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
– Tholle
Nov 9 at 21:59





What does your response data look like? Maybe the response is an object, and you need to access the array with e.g. res.data.result. Maybe the response is also empty if there are no results for the search.
– Tholle
Nov 9 at 21:59













@Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
– lula
Nov 9 at 22:07




@Tholle is a array of posts, i gonna edit and post the response screen. i changed results to posts and the same
– lula
Nov 9 at 22:07




1




1




change .then(res => this.setState( results: res.data )) to res.data.posts
– SakoBu
Nov 9 at 22:11




change .then(res => this.setState( results: res.data )) to res.data.posts
– SakoBu
Nov 9 at 22:11












@SakoBu thank you very much. :)
– lula
Nov 9 at 22:14




@SakoBu thank you very much. :)
– lula
Nov 9 at 22:14












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










res.data will give you the entire parsed JSON response, but you want the array that is the value of the posts property instead.



axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data.posts ))
.catch(() => this.setState( error: true ));





share|improve this answer
















  • 1




    Tholle, thank you man.
    – lula
    Nov 10 at 6:22










  • @lula You're welcome!
    – Tholle
    Nov 10 at 10:46

















up vote
1
down vote













IMO you need use



axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data.posts ))
.catch(() => this.setState( error: true ));


and not



axios
.get("/search?q=" + this.state.term)
.then(res => this.setState( results: res.data ))
.catch(() => this.setState( error: true ));





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233758%2freact-and-this-props-results-map-is-not-a-function%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    res.data will give you the entire parsed JSON response, but you want the array that is the value of the posts property instead.



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data.posts ))
    .catch(() => this.setState( error: true ));





    share|improve this answer
















    • 1




      Tholle, thank you man.
      – lula
      Nov 10 at 6:22










    • @lula You're welcome!
      – Tholle
      Nov 10 at 10:46














    up vote
    2
    down vote



    accepted










    res.data will give you the entire parsed JSON response, but you want the array that is the value of the posts property instead.



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data.posts ))
    .catch(() => this.setState( error: true ));





    share|improve this answer
















    • 1




      Tholle, thank you man.
      – lula
      Nov 10 at 6:22










    • @lula You're welcome!
      – Tholle
      Nov 10 at 10:46












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    res.data will give you the entire parsed JSON response, but you want the array that is the value of the posts property instead.



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data.posts ))
    .catch(() => this.setState( error: true ));





    share|improve this answer












    res.data will give you the entire parsed JSON response, but you want the array that is the value of the posts property instead.



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data.posts ))
    .catch(() => this.setState( error: true ));






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 22:14









    Tholle

    33k53558




    33k53558







    • 1




      Tholle, thank you man.
      – lula
      Nov 10 at 6:22










    • @lula You're welcome!
      – Tholle
      Nov 10 at 10:46












    • 1




      Tholle, thank you man.
      – lula
      Nov 10 at 6:22










    • @lula You're welcome!
      – Tholle
      Nov 10 at 10:46







    1




    1




    Tholle, thank you man.
    – lula
    Nov 10 at 6:22




    Tholle, thank you man.
    – lula
    Nov 10 at 6:22












    @lula You're welcome!
    – Tholle
    Nov 10 at 10:46




    @lula You're welcome!
    – Tholle
    Nov 10 at 10:46












    up vote
    1
    down vote













    IMO you need use



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data.posts ))
    .catch(() => this.setState( error: true ));


    and not



    axios
    .get("/search?q=" + this.state.term)
    .then(res => this.setState( results: res.data ))
    .catch(() => this.setState( error: true ));





    share|improve this answer
























      up vote
      1
      down vote













      IMO you need use



      axios
      .get("/search?q=" + this.state.term)
      .then(res => this.setState( results: res.data.posts ))
      .catch(() => this.setState( error: true ));


      and not



      axios
      .get("/search?q=" + this.state.term)
      .then(res => this.setState( results: res.data ))
      .catch(() => this.setState( error: true ));





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        IMO you need use



        axios
        .get("/search?q=" + this.state.term)
        .then(res => this.setState( results: res.data.posts ))
        .catch(() => this.setState( error: true ));


        and not



        axios
        .get("/search?q=" + this.state.term)
        .then(res => this.setState( results: res.data ))
        .catch(() => this.setState( error: true ));





        share|improve this answer












        IMO you need use



        axios
        .get("/search?q=" + this.state.term)
        .then(res => this.setState( results: res.data.posts ))
        .catch(() => this.setState( error: true ));


        and not



        axios
        .get("/search?q=" + this.state.term)
        .then(res => this.setState( results: res.data ))
        .catch(() => this.setState( error: true ));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 22:12









        A.Vincent

        367




        367



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233758%2freact-and-this-props-results-map-is-not-a-function%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo