Table of Contents generated with DocToc

as

The as attribute is used with the <repeat> and <using> structural components to define a local variable. This variable can be used inside any JSX expressions within the element that defines it.

Here's an example of the as attribute being used with <repeat>:

import { ObservableArray } from "@twist/core";

var numbers = new ObservableArray;

var nodes = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six'];

export default <g>
    <button onClick={ () => numbers.push(Math.floor(Math.random() * 5) + 1) }> Roll </button>
    <br/>
    <repeat collection={ numbers } as={ number } >
       <div> { number } : { nodes[number] } </div>
    </repeat>
</g>;

NOTE: The as attribute is reserved (it has a special semantics), meaning that you shouldn't use it as an attribute name for a custom component - if you do, reactivity won't work as expected.

results matching ""

    No results matching ""