advanced-cropper / react-advanced-cropper

The react cropper library that embraces power of the advanced cropper core to give the possibility to create croppers that exactly suited for your website design
https://advanced-cropper.github.io/react-advanced-cropper/
Other
678 stars 34 forks source link

editor.setState() is working? #38

Closed stylessh closed 1 year ago

stylessh commented 1 year ago

Hello! I want to save the editor state so when I remount it, it saves the previous changes. But it doesn't seem to work.

editorState is the saved state. image image

Here is where I "get" the value store on the useState, but it has the default state anyway. image

Any idea on how can I achieve this?

Norserium commented 1 year ago

@stylessh, could you reproduce the issue in the codesandbox? There is my attempt.

stylessh commented 1 year ago

hey @Norserium, thanks a lot for your response. That is what I want to achieve, but instead I want to restore the previous state when the Cropper is mounted again. If you want I can create a codesandbox

Norserium commented 1 year ago

@stylessh, I assume, that you trying to set state before the cropper loads an image.

To facilitate the implementing of the desired result, you can use the fields from the saved state and pass them to defaultCoordinates, defaultVisibleArea and defaultTransforms.

The codesandbox may be useful.

stylessh commented 1 year ago

I'll try and let you know

stylessh commented 1 year ago

Got it working now man, thanks a lot. Check out the example here so it might help someone in the future.

Now when you save the state, and remount the component, it takes the saved state by default.

https://github.com/advanced-cropper/react-advanced-cropper/assets/45767683/6ebc9574-9271-44db-aa92-a91b307fad13

Norserium commented 1 year ago

@stylessh, you are welcome!