Coder Social home page Coder Social logo

Comments (5)

lilactown avatar lilactown commented on June 20, 2024

The React docs specify that because of the JSX transform logic, not for any internal reason. Take this example:

<foo className="bar baz">qux</div>;

In JSX, it's ambiguous whether the above example should result in creating a React Element using some foo variable (and throw an error if it can't be found), or if it should result in creating a React Element using the string "foo" which the renderer (e.g. react-dom, react-native) knows how to turn into a "native" element.

So the JSX transform has a requirement that all of your components variable names start with UpperCase so that it's unambiguous whether it ought to pass a string to createElement or a variable.

In Helix, we have no such ambiguity because we pass in the exact type we want to create in when creating an element

($ "div") ;; native element
($d "div") ;; native element with DOM prop transformations
($ div) ;; passing in a component bound to the symbol `div`
($d div) ;; passing in a component bound to the symbol `div` with DOM prop transformations

The helix.dom helper macros emit ($d "div") etc.

So we can name our components whatever we want.


For your issue with react-navigation, I would consider opening a ticket with them.

As far as I can tell after skimming the JS source, there's no difference in behavior using a component that starts with an Uppercase vs lowercase other than the warning. I don't know why they took it upon themselves to warn their users, when anyone using JSX should have other ways of being notified about best practices when using that syntax. You can also feel free to ignore the warning.

If the warning is bothering you, you can always name the components you pass to it using an UpperCase name, like

(defnc MyFeature
  [props]
  ,,,)

which should get rid of the warning as well.

from helix.

aiba avatar aiba commented on June 20, 2024

Thank you for the detailed reply! I will open an issue with react-navigation and reference this one.

Unfortunately(defnc UpperCaseName ..) doesn't even work because the component function's .-name becomes the fully qualified namespace name ("myapp$foo$UpperCaseName_render"), so we would need our root namespace to also be capitalized in order to avoid this warning.

from helix.

lilactown avatar lilactown commented on June 20, 2024

aha right 😅. you could manually set the name property then

(defnc my-component
  [props]
  ,,,)

(set! (.-name my-component) "MyComponent"))

For me, I'd probably just ignore the warning, unless it was really obnoxious.

from helix.

aiba avatar aiba commented on June 20, 2024

Seems like (on react-native at least), (set! (.-name my-component) "MyComponent")) does not have an impact on (.-name my-component). Perhaps name is some kind of special javascript property?

I was able to get this to use via js/Proxy, but I was worried about what unexpected issues could be caused by swapping a component for a proxied object.

from helix.

aiba avatar aiba commented on June 20, 2024

For anyone else looking into this issue, I was going to submit an issue to react-navigation, but I failed to reproduce this in a javascript Snack:

https://snack.expo.dev/@aiba/incorrect-warning-repro

I give up.

from helix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.