React.js将状态设置为true或false

时间:2019-06-11 05:33:12

标签: reactjs if-statement state

如何设置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>
  );
};

任何帮助都会非常有帮助。

1 个答案:

答案 0 :(得分:2)

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>
    );
};