条件渲染
render() {
const { isLoggedIn } = this.props;
return (
{isLoggedIn ? <UserLoggedIn /> : <UserLoggedOut />}
);
}
循环遍历
import React from 'react';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
{ id: 3, name: 'Item 3' },
]
};
}
render() {
return (
<div>
{this.state.data.map(item => (
<div key={item.id}>{item.name}</div>
))}
</div>
);
}
}
export default MyComponent;