Git Product home page Git Product logo

Comments (4)

jamiebuilds avatar jamiebuilds commented on May 29, 2024 1

Well, the question here is: Should you even be trying to call container methods?

import React from 'react'
import Counter from './containers/Counter'

function MyApp(props) {
  return (
    <Counter.Provider initialState={props.initialCount}>
      <div>...</div>
    </Counter.Provider>
  )
}

MyApp.getInitialProps = async () => {
  return { initialCount: 999 }
}

from unstated-next.

raymondsze avatar raymondsze commented on May 29, 2024

Why my comment is deleted? I am not native english speaker, if there are any wording not appropriate, sorry for that.

The following is what I would like to say..

If the question is: Can't use Store methods outside of function?
The answer should be It can't as React Hook is living inside functional React Component and Unstated-Next is based on React Hooks.

Is this issue solvable?

Yes and No, to solve this issue, the only way right now is implement the same API like React Hooks provides (may not worth it) and React maintains the whole lifecycle of React component rendering. React could use the global variable reference to implement useXXX hooks. This could only be possible if Unstated-Next has the same assumption that React has, but this makes lots of complexity.

Differences between Unstated and Unstated-Next

Unstated-Next use React Hooks directly while Unstated create a Container class act like React Component but they are not equal. So you can call function of Container using after "new" outside React and then do the dependency injection back. But this cannot be done in Unstated-Next.

Next.js Example

https://github.com/zeit/next.js/blob/master/examples/with-unstated/pages/_app.js
You can see the api could be persist (resetStore, initStore, as well as custom actions if exists) among server-side and client-side. But this also cannot be done with Unstated-Next.

What I would like to say is..
If Unstated-Next aims to be a replacement of Unstated, the above issue should be an issue.
If Unstated-Next is a state management library using React-Hook and have a rule that the state must live in React, then Unstated-Next cannot replace Unstated.
That's why I think both libraries should be exist.

Just like Context API + Hooks Combo cannot completely replace Redux.

from unstated-next.

jamiebuilds avatar jamiebuilds commented on May 29, 2024

@raymondsze Please move to a different issue

from unstated-next.

raymondsze avatar raymondsze commented on May 29, 2024

@jamiebuilds
Created, #20.

from unstated-next.

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.