Skip to content

Latest commit

 

History

History
37 lines (18 loc) · 1.1 KB

StatelessFunctionComponents.md

File metadata and controls

37 lines (18 loc) · 1.1 KB

Functions as Stateless Components

React 0.14 introduced stateless functional components .

In idiomatic React code, most of the components you write will be stateless, simply composing other components. We’re introducing a new, simpler syntax for these components where you can take props as an argument and return the element you want to render

Note : even though we're just creating/passing functions, react internally creates instances and manges them.Currently we don't gain any performance from these infact these are slower than components with shouldComponentUpdate implemented.

Stateless Component with props

 object StatelessComponent {
  
  val component = (props: String) => Text(s"Hello Stateless ${props}")
 
  def apply(props : String) = CreateElementSF(component,props)
  
 }

Stateless Component No Props

 object StatelessComponent {
  
  val component = () => Text(s"Hello Stateless No Props")
 
  def apply() = CreateElementSFNoProps(component)
  
 }