Zaid-Ajaj / Feliz

A fresh retake of the React API in Fable and a collection of high-quality components to build React applications in F#, optimized for happiness
https://zaid-ajaj.github.io/Feliz/
MIT License
544 stars 81 forks source link

Fix #510: Inject React import for components #512

Closed alfonsogarciacaro closed 2 years ago

alfonsogarciacaro commented 2 years ago

This injects import React as "react" in all files declaring a React component as discussed in #510.

Please note this requires the very latest Fable 4 pre-release, still unpublished 😅

@MangelMaxime Imports may become a bit overcrowded, for example when compiling Feliz docs I get (among other imports):

import { createElement, memo } from "react";
import React from "react";
import * as react from "react";

A solution could be to make Feliz helpers import * as React, but this would require upgrading more things for the users. So if there's no issue in the duplicated imports (default React and namespace * as react) we can leave it as is.

MangelMaxime commented 2 years ago

@alfonsogarciacaro

A solution could be to make Feliz helpers import * as React, but this would require upgrading more things for the users.

If we make the change in Feliz, I think this is will not be a breaking change right? So, users will naturally upgrade to it over time.

Imports may become a bit overcrowded, for example when compiling Feliz docs I get (among other imports): So if there's no issue in the duplicated imports (default React and namespace * as react) we can leave it as is.

I don't think having duplicated is having a real impact. Perhaps, just a bit of overload because JavaScript needs to process 2 imports instead of one.

Ideally, if what I said above about not the transition being not a breaking change it would be ideal to do it. In general, I try to keep the generated JavaScript on par with what native JavaScript use in general.

Zaid-Ajaj commented 2 years ago

Published Feliz.CompilerPlugins v2.0.0-prerelease-003 which includes this change, ready to be tested 😄