V
V
Vlad2019-10-31 11:56:45
JavaScript
Vlad, 2019-10-31 11:56:45

How to stop persistent api request?

Good afternoon!
Tell me please.
How to stop persistent api request??
Here is the code.
As I understand it, in "public update ()", you need to write some kind of condition.

class VdcDetailsPage extends React.Component {
    public update(): void {
        this.props.actions.getVdcs();
        this.props.actions.vdcDetailsLoad(this.props.match.params.vdcid);
    }

    public componentDidUpdate(prevProps): void {
        this.update();
    }

    public componentDidMount(): void {
        this.update();
    }

    public render(): React.ReactNode {
        if (this.props.vdcs.loading || !("LIMIT_CPU_COUNT" in this.props.VDC) ) {
            return <div />
        }
        return (
            <Standard title={this.props.intl.formatMessage({ id: 'title.vmdetails' })}>
                {/* eslint-disable-next-line react/jsx-no-undef */}
                <VDCDetails vdcs={this.props.vdcs} VDC={this.props.VDC}/>
            </Standard>
        );
    }
}

export default connect(
    (store): {} => {
        return {
            vdcs: store.vdcs,
            VDC: store.VDC,
        };
    },
    (dispatch): {} => ({
        actions: {
            vdcDetailsLoad: (data): void => vdcDetailsLoad(data, dispatch),
            getVdcs: (): void => getVdcs(dispatch),
        },
    }),
)(injectIntl(VdcDetailsPage));

Screenshot with requests:
5dbaa1bbd1985621650501.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2019-10-31
@supeeeee_r_man

In componentDidUpdate(), it is necessary to compare whether new props have arrived or whether the old ones are being updated.
Read more: https://ru.reactjs.org/docs/react-component.html#c...

A
akyl-kb, 2019-10-31
@akyl-kb

What does the function vdcDetailsLoad(data, dispatch)do?
Most likely this is due to an asynchronous request, vdcDetailsLoad updates the store without waiting for a response from the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question