Skip to main content
Version: 0.0.9

Callback

The Callback prop is a function that is called whenever the user changes any form values in the CalcGatewayForm component. The Callback function receives an object containing the calculation request data, which can be used to send the request to the backend.

It contains the following properties:

  • requestBody: The correct calculation format which is parsed from the user input.
  • requestUrl: The URL where the data should be sent to calculate the request.
  • requestState: The request state, which can be used to initialize the CalcGatewayForm with previous values.

To ensure the calc request functions properly, it is essential to include product ids, which are not provided in the callback. When you receive the callback, you need to enrich the requestBody with the product ids before forwarding the request to the backend. Use the requestBody and requestUrl properties to accomplish this.

Usage

To use the Callback prop, you need to pass a function to the Callback prop of the CalcGatewayForm component. This function will be called whenever the user changes any form values.

import {CalcGatewayForm} from 'kampmann-calcgateway-frontend'

function App() {

//This state is passed as a callback to the CalcGatewayForm component and will store the Request Form result
const [result, setResult] = useState({})

return (
<CalcGatewayForm
...
callback={setResult}
/>
)
}