1

How do I insert the "word" variable into the rendered object as in the code below I have tried the $word and $word but none works

import React, {useState, useEffect} from 'react'

export default function dictionary() {
  const data = {
    "ABATE": {
      "MEANINGS": {
        "2": [
          "Verb",
          "become less in amount or intensity",
          [ "Decrease", "Diminish", "Lessen", "Fall" ],
          [ "The storm abated", "The rain let up after a few hours" ]
        ]
      },
      "ANTONYMS": [],
      "SYNONYMS": [ "Slack off", "Slack", "Abate", "Die away", "Slake" ]
    },
    "ABATEMENT": {
      "MEANINGS": {
        "2": [
          "Noun",
          "the act of abating",
          [ "Moderation", "Mitigation" ],
          [ "laws enforcing noise abatement" ]
        ]
      },
      "ANTONYMS": [],
      "SYNONYMS": [ "Abatement", "Suspension", "Reprieve", "Hiatus", "Respite" ]
    },
  };
  const [word, setWord] = useState('ABATE')

  return ( 
    <>
      <div>
        <label>Word</label>
        <input type="text" value={word} onChange={(e) => setWord(e.target.value)} />
      </div>
      <div className="container pt-n5" >
        <div className="jumbotron d-flex justify-content-center " >
          <div>
            <b> Meaning:</b>
            <p>{data.$`word`?.MEANINGS[0]}</p> {word} <br />
            <b> Meaning:</b>   <p>{data.$word?.MEANINGS[1]}</p>
            <b> Meaning:</b>   <p>{data.$word?.MEANINGS[2]}</p>
          </div>
        </div>
      </div>
    </>
  );
}

1 Answer 1

1

Using the bracket-notation:

data[word]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.