Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Status Text need be display as true React

I am getting output correctly as JSON format. I need to display in this td coloum if the status is coming 1 I need to display it as true otherwise false.

const [tasks, setTasks] = useState([]);

useEffect(() => {
  (async () => await Load())();
}, []);

async function Load() {
  const result = await axios.get("http://localhost:5000/tasks");
  setTasks(result.data);
  console.log(result);
}

result displayed in json format

 {
   "_id": "64ad2fd352f8f6937e4bb6af",
   "title": "task1",
   "description": "task1 sf",
   "duedate": "2023-12-02T18:30:00.000Z",
   "status": "1",
   "__v": 0
 },

what I tried so far I attached below. i am getting result as {task.duedate} this way. i need
if result comes as 1. i need to display it as true and the text color needs to be changed as green

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<td class="px-6 py-4">
    {
     if(task.status === "1"){
      //...
     }
     else{
      //...
     }
    }
</td>

>Solution :

based on task.status you return the coresponding <span>

<td className="px-6 py-4">
  {task.status === "1" ? (
    <span style={{ color: "green" }}>true</span>
  ) : (
    <span>false</span>
  )}
</td>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading