Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Importing multiple React components in submodules fails #104

Closed
benadamstyles opened this issue Dec 8, 2018 · 1 comment
Closed

Importing multiple React components in submodules fails #104

benadamstyles opened this issue Dec 8, 2018 · 1 comment

Comments

@benadamstyles
Copy link
Contributor

This:

module Bold = {
  let component = ReasonReact.statelessComponent("Bold");

  [@genType]
  let make = children => {
    ...component,
    render: _ =>
      <Text style=styles##bold> {ReasonReact.string(children)} </Text>,
  };
};

module Faded = {
  let component = ReasonReact.statelessComponent("Faded");

  [@genType]
  let make = (~opacity=0.7, children) => {
    ...component,
    render: _ =>
      <Text style={Style.style([Style.opacity(Float(opacity))])}>
        {ReasonReact.string(children)}
      </Text>,
  };
};

compiles to this:

// $FlowExpectedError: Reason checked type sufficiently
import * as FormattingBS from './Formatting.bs';

// $FlowExpectedError: Reason checked type sufficiently
import * as ReasonReact from 'reason-react/src/ReasonReact.js';

export type Bold_Props = {|+children?: mixed|};

export const Bold: React$ComponentType<Bold_Props> = ReasonReact.wrapReasonForJs(
  FormattingBS.component,
  (function _(jsProps: Bold_Props) {
     return FormattingBS.make(jsProps.children);
  }));

export type Faded_Props = {|+opacity?: number, +children?: string|};

export const Faded: React$ComponentType<Faded_Props> = ReasonReact.wrapReasonForJs(
  FormattingBS.component,
  (function _(jsProps: Faded_Props) {
     return Curry._2(FormattingBS.make, jsProps.opacity, jsProps.children);
  }));

Both Bold and Faded use FormattingBS.component and FormattingBS.make, but the exports of Formatting.bs.js are:

export {
  Bold ,
  Faded , 
}

so they should use FormattingBS.Bold.component and FormattingBS.Bold.make, and FormattingBS.Faded.component and FormattingBS.Faded.make respectively.

cristianoc added a commit that referenced this issue Dec 9, 2018
Fix issue when exporting nested components where the appropriate module access path into the .bs.js file was not used.

TODO: remove the assumption that “component” is the first item exported in the module.

See: #104.
@benadamstyles
Copy link
Contributor Author

👍 thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant