Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed Oct 9, 2019
1 parent f4ce531 commit 9f8e31f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,30 @@ end

### render
```
render() -> Element | nil
render(props, state) -> Element | nil
```

`render` describes what a component should display at the current instant in time.

```lua
function MyComponent:render(props, state)
-- props == self.props
-- state == self.state
return Roact.createElement("TextLabel", {
Text = "Hello, " .. props.name .. "!"
})
end
```

!!! info
Roact assumes that `render` act likes a pure function: the result of `render` must depend only on `props` and `state`, and it must not have side-effects.

```lua
function MyComponent:render()
function MyComponent:render(props, state)
-- This is okay:
return Roact.createElement("TextLabel", {
Text = self.props.text,
Position = self.state.position
Text = props.text,
Position = state.position
})

-- Ack! Depending on values outside props/state is not allowed!
Expand Down

0 comments on commit 9f8e31f

Please sign in to comment.