react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

onSave on axios request calling axios request again

Open albertogaldames opened this issue 8 years ago • 2 comments

Hi I've made a custom modal where i make an axios post when i click on save button. I call the 'onSave' method when the response is done and valid but it looks like onSave function is calling the axios post again (Without onSave method it's just one call). It's weird because i've achieve this functionality in another component and this is almost a copy paste from the other.

handleSaveBtnClick = () => {
    const { onSave } = this.props;
    const newRow = {
        ...
    };
    axios.post('/api/newRow/', newRow)
        .then((response) => {
            onSave(response.data);
        })
        .catch((error) => {
            console.log(error.response);
        });
    }
render() {
    const { onModalClose } = this.props;
    return (
        ...........
        <ModalFooter>
            <Button className="modal-button modal-button__save" onClick={() => this.handleSaveBtnClick()}>Guardar</Button>
            <Button className="modal-button modal-button__cancel" onClick={onModalClose}>Cancelar</Button>
        </ModalFooter>
    );
}

Am I doing something wrong?

Ps: I don't know how to write the issue to show the code formatted sorry :S

albertogaldames avatar Jan 12 '18 09:01 albertogaldames

@albertogaldames https://guides.github.com/features/mastering-markdown/

crissdev avatar Jan 14 '18 17:01 crissdev

@albertogaldames if you want to sync up the new row into your database, I will not suggest you to doing like this, please enable the remote mode.

remote(remoteObj) {
    // Only insert row will be handled by remote store
    remoteObj.insertRow = true;
    return remoteObj;
  }
 // ...
 <BootstrapTable data={ this.props.data }
                      selectRow={ selectRow }
                      remote={ this.remote }

and call your redux action or axios in the options.onAddRow`, https://github.com/AllenFang/react-bootstrap-table/blob/master/examples/js/remote/remote-alternative.js#L34

AllenFang avatar Jan 19 '18 13:01 AllenFang