P
P
Pogran2016-09-20 15:22:24
JavaScript
Pogran, 2016-09-20 15:22:24

How to execute render with a delay?

I have this code

export class Node extends Component {
  renderChild = childId => {
    const { id } = this.props;

    return (
      <li key={childId}>
        <ConnectedNode id={childId} parentId={id} />
      </li>
    )
  };

  render() {
    const { parentId, childIds, type, _value, _key } = this.props;
    return (
      <div>
        {type == 'object' && _value && <span>&#123;</span>}
        {type == 'object' && !_value && <span><b>{_key} :</b> &#123;</span>}
        {type == 'array' && <span><b>{_key} :</b> [</span>}
        {type == 'object array' && <span>&#123;</span>}
        {type == 'string' && <span><b>{_key} :</b>{_value}</span>}

        {childIds.length && <ul style={{listStyle: 'none', paddingLeft: '24px'}}>
          {childIds.map(this.renderChild)}
        </ul>}

        {type == 'object' && <span> &#125;</span>}
        {type == 'object array' && <span> &#125;</span>}
        {type == 'array' && <span>]</span>}
      </div>
    )
  }
}

function mapStateToProps(state, ownProps) {
  return state.entity.structure[ownProps.id]
}

const ConnectedNode = connect(mapStateToProps, actions)(Node);
export default ConnectedNode;

I need render to be built with a delay. The point is that when there is a very large recursion, the browser eventually freezes. so I think to somehow ease the load by making the minimum load

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KnightForce, 2017-05-15
@KnightForce

setTimeout(()=>{
    //Код - контекст привязал через стрелочную функцию
}, 5000)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question