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
534 stars 78 forks source link

Cluttered imported React hook names #564

Closed ArtemyB closed 8 months ago

ArtemyB commented 1 year ago

Here are the examples of React hook calls currently (Feliz v2.4.1, but I remember the case take place all my Feliz usage): useReact_useCallback_1CA17B65, useReact_useMemo_10C6A43C and so on. Firstly, That doesn't look pretty. And in practice it affects React Dev Tools user experience. Secondly, there is actual JS-code being produced in Feliz bundle, e.g. from fable_modules/Feliz.2.4.1/React.fs.js:

export function useReact_useMemo_10C6A43C(createFunction, dependencies) {
    const arg_1 = defaultArg(dependencies, []);
    return Interop_reactApi.useMemo(createFunction, arg_1);
}
// and so on for the rest of the bindings

As I understand, this would not have happened if the containing React type had Erase attribute (to be erased by Fable). However it will work only when all of the type members are inline. And now I see that alongside the inline "pure" imports React type contains:

The solution doesn't seems to require a lot of work, if it is actually correct -- haven't tried anything yet, just made assumptions based on my previous experience. Decided to ask for other opinions and expertise here before doing something 🙂

Zaid-Ajaj commented 1 year ago

Hi @ArtemyB I understand the generated JS is not ideal by Feliz, however sometimes it is not possible to inline members. I don't remember the exact reasons why some hooks aren't being inlined. That said, a PR would be really appreciated that includes these improvements 🙏