GithubHelp home page GithubHelp logo

Comments (8)

avkonst avatar avkonst commented on August 22, 2024 2

BTW, I use hookrouter with typescript. There are external typings developed by somebody else. No issues so far.

from hookstate.

avkonst avatar avkonst commented on August 22, 2024

Hi! Happy New Year.

I personally use https://www.npmjs.com/package/hookrouter but it is the same sort of things. So can be done.

Do you think this is useful?
Maybe it is useful.

Or it should not be part of hookstate plugins?
I expect plugins can be anything. People may choose what they want and what they do not want to include. My goal is to keep core on purpose and small.

I have got rough ideas how this plugin could work. But could you please elaborate in a bit more details and maybe with code samples how you expect to use / interact with it?

from hookstate.

praisethemoon avatar praisethemoon commented on August 22, 2024

Thanks for pointing out that library! However its owner makes some bold statements of not using typescript 😅

Inspired by that library, I could think of something as follows

 
const routes = {
    '/': () => <HomePage />,
    '/about': () => <AboutPage />,
};

const About = () => {
   const location = useLocation()
   return (
      <button disabled={location.at('/home')}>Go Home</button>
   )
}
  
const MyApp = () => {
    const routeResult = useRoutes(routes, (newRoute => {
         console.log('moving to new route ', newRoute.location)
    }));
    return routeResult || <NotFoundPage />;
}

This may seem as a rewritee of some existing stuff, but I think having hookstate as single dependency for all kind of state is really cool!

from hookstate.

avkonst avatar avkonst commented on August 22, 2024

It can be cool, but hard to achieve. Conceptually, history stack of a browser is also a state. The only plugin I can think of is the one, which does 2-way sync between StateLink and History.

Even if 2-way sync is possible, there are things to think about. For example, Browser History state supports append, drop, replace operations. StateLink.set() would need some context in order to correctly map current route state to History operation.

PS: context feature is planned, I need it for some other things. I exploring it and have got understanding how context will work. Basically, set/merge will receive additional custom user's information about set/merge action. This context will propagate to plugin callbacks.

from hookstate.

avkonst avatar avkonst commented on August 22, 2024

@praisethemoon hi, have you though more about this ticket? I am not sure how to progress it further...

from hookstate.

praisethemoon avatar praisethemoon commented on August 22, 2024

Hi! Well, I honestly still believe that a hookstate router plugin would really be neat! In my app I have a scenario where I would want to redirect pages pased on iosocket income. I didn't figure out of a fix because I did not concentrate on it but it makes me think how cool would it be to have such a feature at disposal. If you think it is unnecessary for the upcoming months then feel free to close the ticket. Otherwise, if there anything I can help with (given my limited knowlede about this) let me know!

from hookstate.

ppwfx avatar ppwfx commented on August 22, 2024

we're using hookrouter in conjunction with hookstate as well, really slim and efficient stack!

from hookstate.

avkonst avatar avkonst commented on August 22, 2024

Hi,

The Hookstate is moving towards version 2. Please read the updated docs here: https://hookstate.js.org/

I have decided to close this ticket as I do not see that Hookstate will integrate with a router in near future. It still does not stop apps to put the current path to the state on navigation and render accordingly.

from hookstate.

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.