Giter VIP home page Giter VIP logo

Comments (8)

koba04 avatar koba04 commented on May 28, 2024

React's new context API might adopt the render props pattern.

reactjs/rfcs#2

This discussion in the RFC might be useful for this proposal. It's a very long threads though😅

It is difficult to type component for HOC.

I agree with you.
Unfortunately, In addition to that, flowtype has some issues related typing with HOC.

facebook/flow#4709

from almin.

azu avatar azu commented on May 28, 2024

Thanks for suggestion :)

from almin.

azu avatar azu commented on May 28, 2024

Instersting approach

https://github.com/thejameskyle/unstated

from almin.

azu avatar azu commented on May 28, 2024

Image(I do not try to implement this image yet...)

import { StoreGroup, Context } from "almin";
const storeGroup = new StoreGroup({
  app: new AppStore(),
  counter: new CounterStore();
});

const context = new Context({ store: storeGroup });

function Counter() {
  return (
    <Subscribe to={[AppStore, CounterStore]}>
      {(app, counter) => (
        <div>
          <span>Count: {counter.state.count}</span>
          <button onClick={() => context.useCase(new DecrementUseCase()).execute()}>-</button>
          <button onClick={() => context.useCase(new IncrementUseCase()).execute()}>+</button>
        </div>
      )}
    </Subscribe>
  );
}

function App() {
  return (
    <Subscribe to={[AppStore]}>
      {app => (
        <div>
          <Counter />
          <label>Amount: </label>
          <input
            type="number"
            value={app.state.amount}
            onChange={event => {
              context.useCase(new IncrementUseCase()).execute();
            }}
          />
        </div>
      )}
    </Subscribe>
  );
}

render(
  <Provider context={context}>
    <App />
  </Provider>,
  window.complex
);

from almin.

azu avatar azu commented on May 28, 2024

Article: React’s ⚛️ new Context API – DailyJS – Medium

from almin.

azu avatar azu commented on May 28, 2024

https://github.com/bvaughn/react/tree/create-component-with-subscriptions/packages/create-subscription

from almin.

azu avatar azu commented on May 28, 2024

Related Context API based design::

from almin.

azu avatar azu commented on May 28, 2024

Implemented @almin/react-context

from almin.

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.