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

Pass in Immutable Objects

Objects passed into components should be immutable.

+new is called on a background thread. It can even be called on multiple threads simultaneously for the same parameters.

If you pass in mutable objects with nonatomic properties, you will introduce thread safety crashes.

Even if you pass in mutable objects that have only atomic properties, you are introducing a logic race condition. Rendering the exact same object twice could result in different outputs, which doesn't make any sense!

Previous
« No Side Effects
Next
Components Can't Be Delegates Directly »
Facebook Open Source Logo
Copyright © 2021 Facebook, Inc.