m-inan / react-upload-gallery

React for Upload Image Gallery. Sorted by drag & drop and Customizable
MIT License
80 stars 44 forks source link

InitialState re render after change #24

Closed kopeclu2 closed 3 years ago

kopeclu2 commented 3 years ago

Hello, i have issue. I need for you to implement rerender RUG state, after initialState change. I need to add images from outside to RUG. Thank you for reply :)

kopeclu2 commented 3 years ago

I think that this is not good idead how to do it. ref.current.setState({ images: [...items, i] })

m-inan commented 3 years ago

Hi @kopeclu2 , If what you want to do is just save the ready image, you can use this.

ref.current.setState({
  images: [
    ...ref.current.state.images,

    ref.current.create({
      done: true,
      name: "Item 1",
      size: "232kb",
      source:
      "https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=4050&q=80"
    })
  ]
});

If you want to upload the file, you can send a File type array to the uploadFiles method.

await ref.current.uploadFiles([file]);
mariosarbinov commented 3 years ago

Hi @m-inan, thank you for the solution. It's great workaround! However the issue still needs to be fixed.

kopeclu2 commented 3 years ago

Thanks :)