frintjs/frint

Proposal: Access to `app` instance synchronously

Open

#424 aperta il 7 lug 2018

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (37 fork)batch import
help wantedproposal

Metriche repository

Star
 (746 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Currently

Components can only access the app instance via observe HoC, which also involves RxJS for streaming props:

import React from 'react';
import { observe } from 'frint-react';

function MyComponent() {
  return <p></p>;
}

export default observe(function (app, parentProps$) {
  return props$;
})(MyComponent);

Proposal

Not everyone needs to work with streaming props, and may only want to be able to access the app instance (which has the providers), and carry on with regular React lifecycle operations.

To achieve that, we can extend frint-react:

1: withApp function

import React from 'react';
import { withApp } from 'frint-react';

function MyComponent() {
  return <p></p>;
}

export withApp((app, props) => <MyComponent />);

2: WithApp component with render prop

This may not be necessary. Just withApp function alone should be enough.

import React from 'react';
import { WithApp } from 'frint-react';

export default function MyComponent() {
  return (
    <WithApp>
    {
      (app, props) => <p></p>
    }
    </WithApp>
  );
}

Guida contributor