Skip to content

Use snake_case for components #779

Description

@Archmonger

Current Situation

We currently promote using PascalCase for components, following ReactJS convention. However, this very much goes against PEP8.

See original discussion:

Proposed Actions

Rewrite the docs to promote snake_case usage.

Activity

  1. added this to the 1.0 milestone on Jul 1, 2022
  2. rmorshea commented on Jul 13, 2022

    @rmorshea
    Collaborator

    We'll need to complete reactive-python/reactpy-flake8#9 in order to resolve this.

  3. modified the milestones: 1.0, on Jan 12, 2023
  4. removed this from the milestone on Jan 29, 2023
  5. JamesHutchison commented on Nov 9, 2023

    @JamesHutchison
    Contributor

    I actually prefer PascalCase because even though the implementation is a decorated function, you're using it like its a class.

  6. Archmonger commented on Nov 10, 2023

    @Archmonger
    ContributorAuthor

    But this makes a lot of linters and IDEs not happy. We shouldn't have to make people modify their linting config to use ReactPy without getting warnings.

  7. JamesHutchison commented on Nov 10, 2023

    @JamesHutchison
    Contributor

    Alright, I did some research then consulted with GPT-4 and it's voting snake_case. Here's that discussion:

    https://chat.openai.com/share/3788cfb9-d017-4659-bbc2-9476400c3e25

    I don't feel strongly about this. It's worth calling out that GPT-4 suggested that pascal vs snake case was a differentiator in tsx / jsx files but I don't see any clear technical reason. I think based on what I know now, the question is whether pyx files may exist in the future and if we want to see this:

    <MyComponent foo="1" />

    or this:

    <my_component foo="1" />

    Aesthetically, PascalCase feels better IMO.

    GPT-4 seems to insist the naming convention is important in React. Again, I'm not sure there's any real technical reason for a theoretical pyx to strictly use one over the other. We're not sure pyx should even exist.

    If you use lowercase for a component name, React will interpret it as a DOM tag. For example, if you have a component named myComponent (with a lowercase 'm') and try to use it in JSX like , React will look for an HTML tag named myComponent, which does not exist, and you will likely get an error or unexpected behavior.

    Here's what would happen:

    React will treat as a regular HTML tag because it's lowercase.
    Since there's no standard HTML tag called myComponent, React will not render anything to the DOM for this tag, or it may throw an error in the console indicating that the tag is not recognized.
    The correct way is always to capitalize custom component names, like MyComponent, to ensure that React treats them as components rather than HTML tags.

    One final side effect to consider is whether strictly following pep8 and existing linters would drive people to use class based components which are more verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-3-lowMay be resolved one any timeline.type-docsAbout changes and updates to documentationtype-investigationAbout research and gathering information

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions