Last active
February 4, 2017 13:14
-
-
Save marg51/1f6e1dd7e9907d5f4c12e729550230e3 to your computer and use it in GitHub Desktop.
ng-repeat with inferno / react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Inferno from 'inferno'; | |
import Component from 'inferno-component'; | |
import './App.css'; | |
import Repeater from "./Repeater" | |
import DisplayProps from "./DisplayProps" | |
class App extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
counter: 0 | |
} | |
} | |
render() { | |
const listOfItems = [{shrug: "oui"}, {shrug: "non"}, {shrug: "hard"}] | |
return ( | |
<div className="App"> | |
<div className="App-header"> | |
<h2>Welcome to Inferno</h2> | |
</div> | |
<button onClick={() => this.setState({counter: this.state.counter+1})}>{this.state.counter}</button> | |
<Repeater loop={listOfItems}> | |
<DisplayProps>content from parent {this.state.counter}</DisplayProps> | |
</Repeater> | |
</div> | |
); | |
} | |
} | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Inferno from "inferno" | |
export default (props) => { | |
return <div style={{marginTop: 30}}> | |
{Object.keys(props).map(keyName => | |
<div> | |
<b>props.{keyName}:</b> | |
<span>{JSON.stringify(props[keyName])}</span> | |
</div> | |
)} | |
</div> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import React from "react" | |
import Inferno from "inferno" | |
export default ({children, loop}) => { | |
return <div>{ | |
loop.map( (props, $index) => | |
<children.type | |
{...props} | |
$index={$index} | |
$last={ $index===loop.length-1} | |
$first={$index===0}> | |
{children.props.children} | |
</children.type> | |
) | |
}</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment