Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs设置状态为true或false_Reactjs_If Statement_State - Fatal编程技术网

Reactjs设置状态为true或false

Reactjs设置状态为true或false,reactjs,if-statement,state,Reactjs,If Statement,State,如何设置loaderSimpleStory()和FlightStatusStory的状态 当loaderSimpleStory()为true时,FlightStatusStory将为false,反之亦然 const LoadingStory = () => { return ( <div className="content-wrapper"> {loaderSimpleStory()} <div className="containe

如何设置loaderSimpleStory()和FlightStatusStory的状态

当loaderSimpleStory()为true时,FlightStatusStory将为false,反之亦然

const LoadingStory = () => {
  return (
    <div className="content-wrapper">
      {loaderSimpleStory()}
      <div className="container-subnav">
        <FlightStatusStory />
      </div>
      <div className="headline">{headlineSimpleStory()}</div>
      {linkSimpleStory()}
      {richTextSimpleStory()}
    </div>
  );
};
const LoadingStory=()=>{
返回(
{loaderSimpleStory()}
{headlineSimpleStore()}
{LinkSimpleStore()}
{richtextsimplestry()}
);
};
任何帮助都会非常有用。

从“React”导入React,{useState,useffect};
import React, {useState, useEffect} from 'react';

const LoadingStory = () => {
    const [status, setStatus] = useState(null);

    useEffect(() => {
        setStatus(loaderSimpleStory()); 
    },[])

    return (
        <div className="content-wrapper">
            {status == null && loaderSimpleStory()}
            <div className="container-subnav">
                {status !== null && <FlightStatusStory status={!status} />}
            </div>
        </div>
    );
};
常数加载存储=()=>{ const[status,setStatus]=useState(null); useffect(()=>{ setStatus(loaderSimpleStory()); },[]) 返回( {status==null&&loaderSimpleStory()} {status!==null&&} ); };
const FlightStatusStory=(props)=>{const{status}=props;//false return();}here return()的原因是什么?写下要从FlightStatusStory返回的jsx。但是loaderSimpleStory()没有在FlightStatusStory之前加载。它应该在之前加载。在我发布的原始代码中,它是一个加载程序,在呈现FlightStatusStory之前将显示加载程序。从loaderSimpleStory()返回的值是否会更改?如果没有,那么您可能会一直被它困扰,除非您使用某种状态或道具更改。@ChristophenGo我需要这样做,当FlightStatusStory状态为true时,loaderSimpleStory()将状态设置为false。