Skip to content

Clarify lifecycle (renderComponent vs. renderComponentToString) #968

Closed
@matthewwithanm

Description

@matthewwithanm

As discussed on IRC, the lifecycle functions are misleading when using renderComponentToString. Namely, because componentWillMount is called, but componentDidMount is not.

At the least, this should be documented on the lifecycle docs page. There was also discussion about changing the method names. (Note: there's clearly a need for both hooks; the only issue is that name of the former conveys that the component will mount when, in fact, it won't.)

One possibility is to add another always-run phase before the mounting phase which is run when rendered to string or DOM (e.g. "prepare" or "initialize"). The lifecycle would then be easily explained as follows:

  1. Prepare the compoent
  2. Mount the component (if rendering to DOM)
  3. Render the component for the first time.

I'd be happy to contribute a PR for either docs, method names, or both once a decision is reached.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions