Coder Social home page Coder Social logo

Comments (6)

FireyFly avatar FireyFly commented on May 6, 2024 4

@satya164 well sure, but it would be defined in terms of the useNavigation hook in this repo, much like the current useNavigationParam is. From the readme:

useNavigationParam(paramName)

Access a param for the current navigation state

function MyScreen() {
  const name = useNavigationParam('name');
  return <p>name is {name}</p>;
}

Literally the same as useNavigation().getParam(paramName)

The hook I proposed is a modification of this, and could be implemented along the lines of

const useNavigationParam = (paramName, defaultValue) => [
  useNavigation().getParam(paramName, defaultValue),
  (newValue) => useNavigation().setParams({ [paramName]: newValue }),
];

but the bit I'm worried about is if the ship has sailed with regard to the API of useNavigationParam. (Since my proposed API wouldn't be backwards-compatible here.)

from hooks.

satya164 avatar satya164 commented on May 6, 2024 3

Makes sense. Agree that useNavigationParam should return a value, setter pair.

from hooks.

FireyFly avatar FireyFly commented on May 6, 2024 1

@benseitz feel free to open a PR! 👍

A simple implementation should be straightforward (something like the above), but I don't really have the time to look at this currently (over this weekend/next week, at least).

from hooks.

satya164 avatar satya164 commented on May 6, 2024

and using it much like I'd use useState.

The code you posted doesn't need to be a hook since it doesn't use any hook specific features like containing state, using context, storing refs etc. Naming it like a hook will be confusing if it's not really a hook.

from hooks.

benseitz avatar benseitz commented on May 6, 2024

@FireyFly Will you implement this feature or do you want me to open a PR? :)

@satya164 How will you handel the break in backwards compatibility? Since it's an alpha and there is no CHANGELOG yet I fear some users might trip over this.

from hooks.

benseitz avatar benseitz commented on May 6, 2024

@FireyFly @satya164 I opened a PR #20 but it still has some problems, so I'd appreciate your help :)

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.