fable-compiler / fable-react-native

Fable bindings and helpers for React Native projects
Apache License 2.0
49 stars 11 forks source link

Hooks and function components? #60

Open evelant opened 4 years ago

evelant commented 4 years ago

fable-react supports function components but it seems they can't be used in fable-react-native. Am I missing something here (likely, I'm new to f#)? My react-native app crashes if I try to use Fable.React.FunctionComponent.Of(...)

 ERROR    TypeError: module.hot.addStatusHandler is not a function. (In 'module.hot.addStatusHandler(function (status) {
        if (status === "apply") (function () {
          cache.clear();
        })();
      })', 'module.hot.addStatusHandler' is undefined)
[Wed Jul 22 2020 11:36:26.377]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Wed Jul 22 2020 11:36:26.377]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Wed Jul 22 2020 11:36:26.377]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling unmountApplicationComponentAtRootTag)
[Wed Jul 22 2020 11:36:26.378]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
alfonsogarciacaro commented 3 years ago

Sorry for the late reply, I don't use react-native often but I guess it should be possible to use the function components. From the error message I guess the error comes from the code we added to interact with Webpack's HMR. Seems like react-native also exposes module.hot functionality with a different API. Wrapping this in a try ... catch should work I guess: https://github.com/fable-compiler/fable-react/blob/815cff886cfe12bca31efd1193f2bf496b77c231/src/Fable.React.FunctionComponent.fs#L22-L27

adelarsq commented 3 years ago

@AndrewMorsillo Did you manage to solve this problem?