Giter Club home page Giter Club logo

Comments (9)

congdoe avatar congdoe commented on July 3, 2024 2

@MuhammadJafarFA17BCS054 - Were you able to resolve your issue. It seems I am having the same issue but for onResult prop.

from react-map-gl-geocoder.

congdoe avatar congdoe commented on July 3, 2024 1

Nvm figured it out
image
image

from react-map-gl-geocoder.

MuhammadJafarFA17BCS054 avatar MuhammadJafarFA17BCS054 commented on July 3, 2024

@SamSamskies can you help me please?

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on July 3, 2024

Hi @MuhammadJafarFA17BCS054, you are already memoizing the handleViewportChange function. However, you are not memoizing the function that you are passing to the filter prop. All objects and functions that are passed as props need to be memoized. https://reactjs.org/docs/hooks-reference.html#usecallback

from react-map-gl-geocoder.

MuhammadJafarFA17BCS054 avatar MuhammadJafarFA17BCS054 commented on July 3, 2024

Hi @SamSamskies , Thankyou for helping me out, but as i said in the start, I am a newbie, i read the article but i still cant figure out how to memoize the function that i am passing to filter prop. Can you help me?

from react-map-gl-geocoder.

MuhammadJafarFA17BCS054 avatar MuhammadJafarFA17BCS054 commented on July 3, 2024

#39 (comment)
I checked this code, I think it was written by you. It has the same error as mine. Can you make a new repo or something addressing the issue?

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on July 3, 2024

You can use the useCallback hook to memoize functions. Without that a new function is created on every render which causes the geocoder to be re-initialized. Another solution would be to define the function outside of your component. That works because the reference to the function won't change every time the component renders.

Thanks for pointing out the issue with the broken sandbox. I fixed it.

from react-map-gl-geocoder.

MuhammadJafarFA17BCS054 avatar MuhammadJafarFA17BCS054 commented on July 3, 2024

Thank You so much @SamSamskies , i got the basic idea what useCallBack do and what memoized functions are. What i am stuck on now is that, how do i call multiple functions (each made using a useCallBack hook) on onResult prop of Geocoder?

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on July 3, 2024

You can wrap both of the functions with another function.

const sayHello = () => console.log("hello");
const sayWorld = () => console.log("world");
const sayHelloWorld = useCallback(() => {
  sayHello();
  sayWorld();
}, []);

from react-map-gl-geocoder.

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.