Giter VIP home page Giter VIP logo

Comments (8)

satya164 avatar satya164 commented on May 2, 2024

I think it's okay to use useNavigationRef for the navigation prop for internal implementation of useFocusEffect in this library,

from hooks.

slorber avatar slorber commented on May 2, 2024

@satya164 I think it will only solve half of the problem for users.

useFocusEffect(useCallback(() => { 
   setParams({something: true});
},[setParams]));

The following code will trigger again and again without a stable setParams (cf #35)

If we don't export this API, people will have to find a solution themselves, like:

const useNavigationRef = () => {
  const navigation = useNavigation()
  const ref = useRef(navigation);
  useLayoutEffect(() => {
    ref.current = navigation;
  });
  return ref;
}; 
const navigationRef = useNavigationRef();
useFocusEffect(useCallback(() => { 
   navigationRef.setParams({something: true});
},[navigationRef]));

So basically they end up re-implementing the internally used useNavigationRef hook

from hooks.

dngconsulting avatar dngconsulting commented on May 2, 2024

Is there any update on this issue ? I'm currently facing the problem and the previous solution (with useNavigationRef) doesn't work for me (I'm using 1.1.0).
thanx
Sami

from hooks.

slorber avatar slorber commented on May 2, 2024

hi @dngconsulting can you share a repro using useNavigationRef ?
What exactly isn't working, you have an infinite loop or something?

from hooks.

dngconsulting avatar dngconsulting commented on May 2, 2024

Yes absolutely, an infinite loop, I have managed to do it in another way with useEffect and deps array parameter. Thanks.

from hooks.

slorber avatar slorber commented on May 2, 2024

Hi,

Do you remember what was the problem with your code? Is there something wrong in this lib or was it your fault?

from hooks.

dngconsulting avatar dngconsulting commented on May 2, 2024

Frankly speaking I didn't dedicated too much time to this issue because it was flagged here. For me, it's not possible to update the navigation object (with setParam) when you are in FocusEffect hook. You can reproduce it very easily, by changing dynamically the title header of react-navigation in the hook. Hoping that react navigation next will ship soon ...

from hooks.

slorber avatar slorber commented on May 2, 2024

Are you sure you were using useCallback inside useFocusEffect ? It's important to provide a stable callback to useFocusEffect

The useFocusEffect of navigation next is quite similar in behavior because it has been backported from v5 to v4. If there's something that does not work well, it would be nice to report it nicely here so that we can eventually fix it in v5 too before an official release.

from hooks.

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.