'Move component in a div to another div when clicked in react

Let's say I have one component that only holds an image and two divs, one holding the componenet, laid out as such:

enter image description here

Upon being clicked, the component will move into the other div enter image description here

Then when the component is clicked again, it moves back to its original spot, like such: enter image description here

What would the logic be in order to accomplish this? Any help would be appreciated especially with code examples.



Solution 1:[1]

You can refer to my codesandbox link: https://codesandbox.io/embed/magical-minsky-bx681m?fontsize=14&hidenavigation=1&theme=dark

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thitbachi