第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在反應(yīng)JS中異步呈現(xiàn)內(nèi)容

在反應(yīng)JS中異步呈現(xiàn)內(nèi)容

哈士奇WWW 2022-09-11 20:19:52
基本上,我有一組動態(tài)表,這些表是根據(jù)傳遞的值顯示的。如果傳遞了一個空數(shù)組,它應(yīng)顯示“未找到數(shù)據(jù)”。在我的情況下,當(dāng)我向表發(fā)送數(shù)據(jù)時,所有表將首先顯示“未找到數(shù)據(jù)”,然后是實際的表內(nèi)容。我不確定是什么原因造成的。數(shù)據(jù)是異步加載的,它顯示沒有找到的數(shù)據(jù),然后顯示實際內(nèi)容。我添加了 setInterval 來展示這種異步特性沙盒:https://codesandbox.io/s/react-table-row-table-ryiny?file=/src/index.js:0-1322有人可以幫助我嗎?父母import * as React from "react";import { render } from "react-dom";import DataGrid from "./DataGrid";const d1 = [{ name: "test", age: "20" }, { name: "test1", age: "15" }];const d2 = [{ area: "area", pin: "123" }, { area: "area1", pin: "1245" }];const c1 = [  { Header: "Name", accessor: "name" },  { Header: "Age", accessor: "age" }];const c2 = [  { Header: "Area", accessor: "area" },  { Header: "Pin", accessor: "pin" }];const d3 = [];const c3 = [];class App extends React.Component {  constructor(props) {    super(props);    this.state = {      data1: [],      column1: [],      data2: [],      column2: [],      data3: [],      column3: []    };  }  componentDidMount() {    setTimeout(() => {      this.setState({        data1: d1,        column1: c1      });    }, 2000);    setTimeout(() => {      this.setState({        data2: d2,        column2: c2      });    }, 2500);    this.setState({      data3: d3,      column3: c3    });  }  render() {    return (      <>        <DataGrid data={this.state.data1} columns={this.state.column1} />        <DataGrid data={this.state.data2} columns={this.state.column2} />        <DataGrid data={this.state.data3} columns={this.state.column3} />      </>    );  }}孩子import * as React from "react";import ReactTable from "react-table";import "react-table/react-table.css";export default class DataGrid extends React.Component {  constructor(props) {    super(props);    this.state = {      showMore: false    };  }  toggleState = () => {    this.setState(prevState => ({      showMore: !prevState.showMore    }));  };
查看完整描述

2 回答

?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗 獲得超2個贊

在上面的答案中補充幾點。

它以這種方式運行的原因不是因為異步行為,而是 React 組件的生命周期性質(zhì)。

  • 數(shù)據(jù)網(wǎng)格以數(shù)據(jù)的初始狀態(tài)呈現(xiàn),即空[]數(shù)組。

  • 不顯示任何數(shù)據(jù),因為空 [] 數(shù)組在此循環(huán)中傳遞。

  • 然后,您將在組件DidMount中設(shè)置狀態(tài)。

  • 為了顯示效果,數(shù)據(jù)網(wǎng)格再次使用實際數(shù)據(jù)重新呈現(xiàn)。


查看完整回答
反對 回復(fù) 2022-09-11
?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗 獲得超6個贊

使用而不是空數(shù)組(沙盒)初始化應(yīng)用狀態(tài)的數(shù)據(jù):null


this.state = {

  data1: null,

  column1: [],

  data2: null,

  column2: [],

  data3: null,

  column3: []

};

在 DataGrid 中,檢查值是否為虛假(計數(shù),但空數(shù)組為真實),如果是,則返回(無需呈現(xiàn)任何內(nèi)容):methodnullnull


render() {

  const { data, columns } = this.props;


  if (!data) return null;


查看完整回答
反對 回復(fù) 2022-09-11
  • 2 回答
  • 0 關(guān)注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號