fable-react-native icon indicating copy to clipboard operation
fable-react-native copied to clipboard

Hooks and function components?

Open evelant opened this issue 5 years ago • 2 comments

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)

evelant avatar Jul 22 '20 15:07 evelant

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

alfonsogarciacaro avatar Jul 30 '20 06:07 alfonsogarciacaro

@AndrewMorsillo Did you manage to solve this problem?

adelarsq avatar Sep 02 '20 18:09 adelarsq