Menu
ComponentKit LogoComponentKit
DocsInfrastructureAPIGitHub
ComponentKit LogoComponentKit
  • Docs
  • Infrastructure
  • API
  • GitHub
  • Getting Started
    • Getting Started
    • Philosophy
    • Uses
  • Reference
    • Component API
    • Composite Components
    • Views
    • Responder Chain
    • Actions
    • State
    • Scopes
    • Component Controllers
    • Lifecycle Methods
    • Debugging
  • Animations
    • General Principles
    • Initial / Final Animations
    • Change Animations
    • Legacy APIs
  • Collection Views
    • Overview
    • Basics
    • Changeset API
    • Gotchas
    • Dive Deeper
  • Best Practices
    • Never Subclass Components
    • Avoid Overrides
    • Indentation
    • Avoid Local Variables, Use Const
    • Avoid Single Use Constants
    • No Underscores
    • Pass in Actions
    • No Side Effects
    • Pass in Immutable Objects
    • Components Can't Be Delegates Directly
    • Avoid Excessive Branching
    • Check for Nil
    • Avoid push_back
    • Under 300 Lines
    • Avoid Width 100%
    • Use Designated Initializer Style
    • Break Out Composite Components
    • Keep Controller in Component
  • Appendix
    • Why C++
    • Advanced Views
    • Component Context

No Side Effects

Your +new method should not modify any global variables or global state. This could result in a component returning different results for the same parameters, which would be strange.

If you're a functional programming nerd, you can think of +new as a pure function mapping from a set of input parameters to a component. (Pure functions have many benefits, which I won't attempt to outline here.)

Previous
« Pass in Actions
Next
Pass in Immutable Objects »
Facebook Open Source Logo
Copyright © 2021 Facebook, Inc.