When i remove images from news i catch id, and id come to along. How to write in array all this lonlies id ? How to create streamIds array with streamId ?

this.state = {
            mainImage: null,
            mainImageUrl: "",
            crop: {
                aspect: 2 / 1
            },
            pixelCrop: null,
            cropped: false,
            loaded: false,
            streamIds: []
        };

removeImage(imageKey, streamId) {
        const {singleNews} = this.props;
    let streamIds = this.state.streamIds;
        console.log(streamId);

    singleNews.secondaryImages.splice(imageKey, 1);

    if (!singleNews.secondaryImages.length) {
        singleNews.secondaryImages = null;

        delete singleNews.secondaryImages;

        this.props.updateSingleNews(null, singleNews);
    } else {
        streamIds.push(streamId);
        singleNews.secondaryImages.map(image => {
            const index = singleNews.secondaryImages.indexOf(image);

            if (index > -1) {
                singleNews.secondaryImages.slice(index, 1);

                FilesApi.getDocument(image.streamId).then(resp => {
                    singleNews.secondaryImages[index] = new File([resp], image.name, {lastModified: Date.now()});
                });
            }

        });
        this.props.updateSingleNews('streamIds', streamIds);
    }
}

this is your method

If not in this func where i need to place

1 Answers

1
Vilsad P P On

if you want to keep the array of ids in the same component, use

let streamIds = [];

at the top of your react component and do

removeImage (imageKey, streamId) {
   console.log(streamId);
   streamIds.push(streamId); // insert the item to array
}

in your removeImage method

if you want to keep the removed ids in the application state, then the concept is the same, but it need to be done on the state management tool you are using (like redux, mobx etc)