-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactComponent attribute does not work without calling ofFunction
where used
#544
Comments
Also, a major source of frustration with all of this is that I don't see any documentation explaining that |
Hello @sonicbhoc, |
Oh, right. You might need to see that.
|
I am confident that you should not need the Are you sure that all your components that call a hooks are decorated with It would be nice if you could remove your If possible it would be even better if you can remove the code that doesn't cause the problem so we can focus on the problematic code with you. Sorry to ask all that but that's to help you debug the issue and identify it so we can explain it or fix it if needed. |
Seeing You shouldn't need Can you share your package references here, better yet a repro with your project? Cause if ou are using a recent Feliz.CompilerPlugins v2.x and not the one that Feliz v1.68 depends on, then it won't work |
My paket lockfile definitely pinned Feliz.CompilerPlugins 2.0. Thanks for the hint. I'll let you know if that fixes it. |
That did the trick! I locked the version of Feliz.CompilerPlugins to ~> 1 in the paket.dependencies file and included it in my paket.references file. (That step is important; otherwise it still doesn't work.) Thank you! |
I closed the issue, but I just thought about something. The documentation should be updated to inform people that don't use the template to start a new project that they not only need to pull this library in as part of their paket dependencies, but also include them in the project, and ensure that the version of CompilerPlugins is ~> 1 for Feliz 1.68 and 2 for newer versions. I would also love to see the package itself updated on nuget to depend on versions >1.10 and < 2. |
I am running into the same issue with the ReactComponent attribute applied and a simple I have made a minimal Repro with only Feliz and the latest Fable: (@Zaid-Ajaj @MangelMaxime) To test it: git clone [email protected]:panmona/fable3-esbuild.git
git checkout repro-hooks-reactcomponent
yarn
yarn start
# go to http://localhost:3000 I feel like this could have something to do with the changes to ReactComponent in #506 ? (@alfonsogarciacaro) // .build/App.js
var import_react4 = __toESM(require_react());
var import_client = __toESM(require_client());
function TabCounter() {
const patternInput = Feliz_React__React_useState_Static_1505(0);
const setCount = patternInput[1];
const count = patternInput[0] | 0;
React_useEffect_3A5B6456(() => {
document.title = toText(printf("Count = %d"))(count);
});
const children = ofArray([(0, import_react4.createElement)("h1", {
children: [count]
}), (0, import_react4.createElement)("button", {
children: "Increment",
onClick: (_arg1) => {
setCount(count + 1);
}
})]);
return (0, import_react4.createElement)("div", {
children: Interop_reactApi.Children.toArray(Array.from(children))
});
}
var root = (0, import_client.createRoot)(document.getElementById("elmish-app"));
root.render(TabCounter()); |
When starting a new project from scratch requesting The request made by @sonicbhoc is indeed important. The workaround is to manually restrict the version of |
Actually the same goes for |
@MangelMaxime Feliz doesn't depend on the main Fable.React library, only the types |
Were you able to reproduce the behavior with the demo I linked above ( https://github.com/panmona/fable3-esbuild/tree/repro-hooks-reactcomponent ) and maybe have an idea what the underlying could be? |
I found out that I didn't use the latest Fable Tool version. (theta-007 instead of theta-018) So I think that this issue is now solved. |
So I am having a strange issue with Feliz 1.68 and Fable 3.7.1.
I'm trying to author React components. When I just add the
[<ReactComponent>]
attribute to an F# function with a capital name and a list of properties (which is usually empty), I'm expecting it to generate a React Function Component. But the generated component's logic is essentially comprised of constructing arrays like what's in the F# code. Which is fine, except my React components don't work.In every example I've seen, all I am supposed to need is the ReactComponent Attribute and supposedly I'd get a function component, and then I can just call that component like a function. But when I do that, I get this error:
Invalid hook call. Hooks can only be called inside of the body of a function component.
And the generated code looks like this:
In order to get anything to work at all, I have to use the
ofFunction
function everywhere I use a ReactComponent, which I thought the attribute was supposed to do for me. Then, the generated code looks like this:This works, but now I get a different set of warnings that I have no idea how to resolve:
Each child in a list should have a unique "key" prop.
I don't know how to add a key prop, because I need to return
ReactElement
and props areIReactProperty
.Also, as an aside, what are the benefits of moving to Fable 4 + Feliz 2 in terms of writing a React program?
The text was updated successfully, but these errors were encountered: