score:1

Accepted answer

You can update your loadMoreResources function like that to remove all duplicates from the state.

loadMoreResources = () => {
        let {page,resources} = this.state;
        let newPage = page +1;
        this.setState({page: newPage})
        this.props.getResources(undefined,undefined,newPage).then((res) => {
            let ids = res.data.map(o => o.id)
            let stateWithoutDuplicates = resources.filter(({id}) => !ids.includes(id))
            if(res.meta && (res.meta.current_page < res.meta.last_page)){
                this.setState({hasMoreItems:true})
            }else this.setState({hasMoreItems:false})
            this.setState({
                resources: [...stateWithoutDuplicates,...res.data]
            })
        })
    }

score:1

If you know where in the array it needs to be added you can just update state pretty similar to what you were doing when fetching data

this.setState({
  resources: [newItem,...this.state.resources]
})

If you are adding to the top and your server is returning the same item again you can try and use the same key prop for both items. If they both have the same key React won't render them twice


Related Query

More Query from same tag