Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- class UserList extends Component {
- constructor( props ) {
- super( props );
- this.state = {
- users: props.users
- };
- }
- componentWillReceiveProps( nextProps ) {
- if ( this.props !== nextProps ) {
- const { users } = nextProps;
- users.then( users => {
- this.setState( {
- users
- } );
- } );
- }
- }
- render() {
- const { users } = this.state;
- if ( !users ) {
- return (
- <div>
- Ładuję...
- </div>
- );
- }
- return (
- <ul>
- { users.map( user => {
- return (
- <li key={user}>{user}</li>
- );
- } ) }
- </ul>
- );
- }
- }
- export default UserList;
Advertisement
Add Comment
Please, Sign In to add comment