Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Invalid shorthand property initializer with a variable int

when I run my code, I get the following error:

Invalid shorthand property initializer.

function DisplyayNote() {
    let noteId = -1;
    const [isOpen, setIsOpen] = useState(false);

    return isOpen ? (
        {noteId = 0 ? <div className="backComponent">
        <div className="noteOpen">
            <div>C'est ouvert</div>
            <button onClick={() => setIsOpen(false)}>Fermer</button>
        </div>
    </div> : null}
    ) : (
        <>
            <div>C'est fermé</div>
            <button onClick={() => setIsOpen(true)}>Ouvrir</button>
        </>
    );
}

Would you have an idea to solve this problem?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

First of all, there is no need to add {. Second, change note_id=0 to note_id==0 or note_id===0 because note_id=0 is not a boolean expression. I have used the code snippet below to test it and its working fine.

function DisplyayNote() {
    let noteId = 0;
    const [isOpen, setIsOpen] = useState(false);

    return isOpen ? (

        noteId == 0 ? <div className="backComponent">
            < div className="noteOpen" >
                <div>C'est ouvert</div>
                <button onClick={() => setIsOpen(false)}>Fermer</button>
            </div >
        </div > : null

    ) : (
        <>
            <div>C'est fermé</div>
            <button onClick={() => setIsOpen(true)}>Ouvrir</button>
        </>
    );
};

working image

about 4 years ago · Juan Pablo Isaza Report

0

Please change noteId = 0 to noteId === 0

about 4 years ago · Juan Pablo Isaza Report

0

In short, it was enough to put everything in a container:

return isOpen ? (
        <>
        {noteId >= 0 ?
            <div className="backComponent">
                <div className="noteOpen">
                 <div>C'est ouvert</div>
                     <button onClick={() => setIsOpen(false)}>Fermer</button>
                </div>
            </div> : null}
        </>
    ) : (
        <>
            <div>C'est fermé</div>
            <button onClick={() => setIsOpen(true)}>Ouvrir</button>
        </>
    );

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!