Giter Club home page Giter Club logo

Comments (3)

josepholiveira avatar josepholiveira commented on July 24, 2024

Hello @pedrohasf!

I did not understand the issue, why would it not go throught the setSearchValue? The fireEvent.changeText should trigger the onChangeText on the input, and by that you could update the searchValue by calling the setSearchValue.

Upon calling the setSearchValue you would also trigger the useEffect, by adding the searchValue in it's dependency array.

If you could give us code examples, or a little video showing the problem happening we should be able to see if the problem is something else.

from bootcamp-gostack-desafios.

pedrohasf avatar pedrohasf commented on July 24, 2024

Hello @josepholiveira
My useEffect function is as follow:

useEffect(() => {
   async function loadFoods(): Promise<void> {
     if (searchValue && !selectedCategory) {
       const response = await api.get(`foods?name_like=${searchValue}`);
       setFoods(response.data);
       return;
     }
     if (selectedCategory && !searchValue.length) {
       const response = await api.get(
         `foods?category_like=${selectedCategory}`,
       );
       setFoods(response.data);
       return;
     }
     if (searchValue.length && selectedCategory) {
       const response = await api.get(
         `foods?name_like=${searchValue}&category_like=${selectedCategory}`,
       );
       setFoods(response.data);
       return;
     }
     if (!searchValue.length && !selectedCategory) {
       const response = await api.get('foods?name_like=');
       setFoods(response.data);
     }
   }

   loadFoods();
 }, [selectedCategory, searchValue]);

I have debugged and i saw that the variable searchValue on testing reaches the useEfffect function but with its value as an empty string and not as 'Ao molho' as the test needed it to be. I am not entirely certain that this is the problem but i believe it is, for searchValue to be an empty string it must not have been through setSearchValue.

Thanks for the support.

from bootcamp-gostack-desafios.

josepholiveira avatar josepholiveira commented on July 24, 2024

Could you upload your code to github or message me on discord so i can take a better look at it?

Testing in my code returned me the correct searchValue, and i would like to take a look at it. My discord user is DOGIM#0985.

from bootcamp-gostack-desafios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.