Что делает “на ошибке goto 0”, и “ошибка возобновляется затем” в старом среднем ASP?

Пользовательское значение визуализируется изнутри UserContext асинхронно и не будет доступно, пока не будут выполнены дочерние элементы, и, следовательно, вам нужно реализовать componentDidUpdate в ItemProvider, чтобы получить значение контекста, основанное на пользовательской подпорке

import React from "react";

const { Provider, Consumer } = React.createContext();

const items = { 1: { name: "a red hat" }, 2: { name: "a blue shirt" } };

const getItemByUserId = userId => items[userId];

class ItemProvider extends React.Component {
  state = {
    isLoading: false,
    value: { item: {} }
  };

  async componentDidMount() {
    if (this.props.user && this.props.user.id) {
      this.setState({ isLoading: true });
      const item = getItemByUserId(this.props.user.id);
      this.setState({ value: { item }, isLoading: true });
    }
  }

  componentDidUpdate(prevProps) {
    console.log(this.props.user, prevProps.user);
    if (prevProps.user !== this.props.user) {
      const item = getItemByUserId(this.props.user.id);
      this.setState({
        value: { item }
      });
    }
  }

  render() {
    const { isLoading, value } = this.state;
    if (isLoading) {
      return 
Loading data...
; } console.log(value); return {this.props.children}; } } export { ItemProvider, Consumer as ItemConsumer };

[114 ] Рабочая демонстрация

5
задан Joel Coehoorn 1 December 2011 в 20:02
поделиться

2 ответа

On error resume next: If there is an exception in the program, just ignore it and continue to the next statement. Considered very bad and ugly, and rightly so in my opinion. It's like having a big:

try
{
  // your code
}
catch
{
  // nothing! muhaha
}

in every method of your code (or worse, around the whole program).

On error goto 0: disables any error handler that is defined in the current procedure. It's like having a big try-catch around your code, which gets disabled as soon as its hit this line.

For more information, see the MSDN.

5
ответ дан 18 December 2019 в 14:51
поделиться

on error go to takes the execution code to a specific code book mark defined in the page.this is useful when you want to perform anything in case an error is encountered.

On error resume next moves on to the next code of execution after the erroneous code. Basically ignores the error and continues with the code. This is particulary useful when you are processing 100s of records and don't want the code to stop execution in case any record throws up error.

3
ответ дан 18 December 2019 в 14:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: