How to use the fusion-react.useService function in fusion-react

To help you get started, we’ve selected a few fusion-react examples, based on popular ways it is used in public projects.

github fusionjs / fusionjs / fusion-plugin-font-loader-react / src / with-font-loading.js View on Github external
function FontLoader(props: any, ref: any) {
      const mounted: {current: ?boolean} = useRef(null);
      const getFontDetails = useService(FontLoaderReactToken);
      if (typeof getFontDetails !== 'function') {
        throw new Error(
          `withFontLoading not supported. This might be because you set \`withStyleOverloads\`
    to true in the font loader config`
        );
      }
      const {fallbackName, styles} = getFontDetails(fontName);
      const initialFontStyles = fallbackName
        ? // switch to fallback name and apply styles to trigger faux font rendition
          {fontFamily: fallbackName, ...styles}
        : // no fallback so just apply true font
          {fontFamily: fontName};

      const [fontStyles, setFontStyles] = useState(initialFontStyles);

      useEffect(() => {
github fusionjs / fusionjs / fusion-plugin-rpc-redux-react / src / hoc.js View on Github external
function WithRPCRedux(props: Props) {
      const reactReduxContext = React.useContext(ReactReduxContext);
      const ctx = React.useContext(FusionContext);
      const reduxPlugin = useService(ReduxToken).from(ctx);
      const rpc = useService(RPCToken).from(ctx);
      const wrappedMapStateToParams =
        mapStateToParams &&
        ((state, args) => mapStateToParams(state, args, props));
      const store = reactReduxContext
        ? reactReduxContext.store
        : reduxPlugin.store;
      const handler = createRPCHandler({
        rpcId,
        rpc,
        store,
        actions,
        mapStateToParams: wrappedMapStateToParams,
        transformParams,
      });
      return React.createElement(Component, {...props, [propName]: handler});
github fusionjs / fusionjs / fusion-plugin-rpc-redux-react / src / hoc.js View on Github external
function WithRPCRedux(props: Props) {
      const reactReduxContext = React.useContext(ReactReduxContext);
      const ctx = React.useContext(FusionContext);
      const reduxPlugin = useService(ReduxToken).from(ctx);
      const rpc = useService(RPCToken).from(ctx);
      const wrappedMapStateToParams =
        mapStateToParams &&
        ((state, args) => mapStateToParams(state, args, props));
      const store = reactReduxContext
        ? reactReduxContext.store
        : reduxPlugin.store;
      const handler = createRPCHandler({
        rpcId,
        rpc,
        store,
        actions,
        mapStateToParams: wrappedMapStateToParams,
        transformParams,
      });
      return React.createElement(Component, {...props, [propName]: handler});
    }

fusion-react

FusionJS entry point for React universal rendering

MIT
Latest version published 2 months ago

Package Health Score

74 / 100
Full package analysis

Similar packages