mercredi 4 mars 2020

React - How can I set "message from me"

I have 2 states:

const [formData, setFormData] = useState({ input: null });
const [outputData, setOutputData] = useState({ output: null });

formData is coming from my < input />. So, I am writing the input data by writing. outputData is coming from my GET api call.
I need to separate input data and output data. How can I tell the function if the message is from me?

function renderMessage(message) {
    //const here
    if (messageFromMe) {
      return <Me />;
    } else {
      return <You />;
    }
  }

  function Me(props) {
    return (
      <li className="Messages-message currentMember">
        <div className="Message-content">
          Hey its me
        </div>
      </li>
    );
  }

  function You(props) {
    return (
      <li className="Messages-message">
        <div className="Message-content">
          Test
        </div>
      </li>
    );
  }

Aucun commentaire:

Enregistrer un commentaire