2

So at the beginning I know this code is messy. I have a div that I want to copy, when I click on the div, it opens up a Content and it copies that div. The thing I can't seem to accomplish is this, In that copied version of div/Image, I can close the content, but when I press on it again, I can't seem to open the component. If you don't fully understand it here is the sandbox https://codesandbox.io/s/confident-lake-uovir?file=/src/App.js

1 Answer 1

2

You have ref in the first div so the click event can be checked with handleProject.

There are 2 functions run when you click the copied version.
onClick of the div triggers setIsProjectOpen(true), then the eventListenter you added to useEffect triggers setIsProjectOpen(false).
You can do this:

        <div
          onClick={(e) => {
            e.stopPropagation();
            setIsProjectOpen(!isProjectOpen)}};
          className={
            "smallProjects__container " + (isProjectOpen ? "active" : "")
          }
        >
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.