, React , .
, React .
, ? : , , , ..
: , . ListEntry . ? - , SomeList, .
, : React.Component, - . " " :
function MyComponent(props) {
(...some logic...)
return <option>{ props.value }</option>;
}
ES6:
const MyComponent = props => {
(...some logic...)
return <option>{ props.value }</option>;
}
, :
const MyComponent = props => <option>{ props.value }</option>;
, render ( ), :
class SomeList extends Component {
render() {
const ListEntry = props => <option>{ props.value }</option>;
return (
<select>
{ [...Array(10).keys()].map(x => (
<ListEntry key={x} value={Math.random()} />
))}
<ListEntry value="basic" />
<ListEntry value="another" />
</select>
);
}
}
ListEntry SomeList. ( : , render - , ).
, . ListEntry , <option> ListEntry?
:
const SomeList = () => {
return (
<select>
{ [...Array(10).keys()].map(index => (
<option key={index}>{ Math.random() }</option>
))}
<option>Basic</option>
<option>Another</option>
</select>
);
};
SVG: , :
const SomeSvg = () => {
const SmallCircle = props => (
<circle {...props} r="5" stroke="blue" fill="dodgerblue" strokeWidth="2" />
);
const BigCircle = props => (
<circle {...props} r="100" strokeWidth="7" fill="grey" />
);
const randomCoords = (n, domain) => [...Array(n).keys()].map(() => ({
x: Math.floor(Math.random() * domain + 1),
y: Math.floor(Math.random() * domain + 1)
}));
return (
<svg width="700" height="700">
{ randomCoords(5000, 700).map((xy, i) => <SmallCircle key={i} cx={xy.x} cy={xy.y} />) }
<BigCircle cx="1" cy="1" stroke="orange" />
<BigCircle cx="700" cy="700" stroke="green" />
<BigCircle cx="1" cy="700" stroke="red" />
<BigCircle cx="700" cy="1" stroke="blue" />
<SmallCircle cx="200" cy="200" />
</svg>
);
};