react-through
  • README
  • Introduction
    • Motivation
    • Core Concepts
  • Basics
    • Installation and setup
    • Direct Mapping
    • Many Agents
  • Glossary
  • API Reference
    • ThroughProvider
    • createAgent
    • createAdvAgent
    • Through
    • throughDirect
    • throughArea
    • throughContainer
    • Internals
      • Internal Agent Interface
Powered by GitBook
On this page
  • Props
  • Examples
  • Render data from each agent separtely
  • Render data using whole area
  1. API Reference

Through

PreviouscreateAdvAgentNextthroughDirect

Last updated 5 years ago

Render Props based component to receive data in the though-container. It pass props received from the through-agent to a function. The Function as Child Compnent (FaCC) approach is used.

Props from selected agent or whole area if bearingKey (or direct) prop is not specified.

Props

  • area: String: The name of the area see

  • bearingKey: String|undefined: define which agent data is selected, or whole area data if undefined

  • direct: String|bool|undefined: same as bearingKey but also boolean is allowed and true is replaced with default for

  • default|defaultValue: any: default value passed to the render function if no such agent exists or in initial rendering

  • children: function(props|area: Object): props from agent selected by bearingKey or direct or whole area if not specified

Examples

Let Agent is declared and two instanece of it are rendered some where in react tree like this:

const Agent = createAdvAgent('myarea', 'id')

...
<Agent id='first' text='hello'/>
<Agent id='second' text='world'/>
...

Render data from each agent separtely

<Through area='myarea' direct='first' default={{text: 'loading...'}}>
  { ({id, text}) => <p>{text}</p> }
</Through>
<Through area='myarea' direct='second' default={{text: 'loading...'}}>
  { ({id, text}) => <p>{text}</p> }
</Through>

Render data using whole area

<Through area='myarea'>
  {(area) => {
    <div>
      { ( area['first'] || {text: 'loading...'} ).text }
      { ( area['second'] || {text: 'loading...'} ).text }
    </div>
  }
</Through>
Glossary
direct mapping