Loading...
Loading...
Loading...
Loading...
Loading...
We can develop custom React hooks like useCustomAPIMutationHook
to fine-tune the application API interactions. The custom hooks allow us to control how data is fetched and managed, aligning it perfectly with our requirements.
This custom hook, useCustomAPIMutationHook
, simplifies API calls for mutation operations in React applications using react-query
. It allows parameter and body customization for requests to a specified URL, seamlessly managing loading indicators and states. This hook streamlines API interaction and state management within components.
Create useCustomAPIMutationHook
under the following path:
To override the useCustomAPIMutationHook
, create a new custom hook with the desired enhancements. When considering overriding useCustomAPIMutationHook
, identify specific modifications required, such as adding additional parameters or altering data processing logic. Create a new custom hook, preserving the original functionality while incorporating these modifications to suit specific application needs.
We need to replace the usage of the original hook throughout the codebase with the new custom hook. This ensures that wherever the original hook is used, the modified functionality of the custom hook is applied instead.
There is a hook called useCustomMDMSV2
, which is used to get data from a Multi-Domain Master Service (MDMS) API. This hook makes it easier to request data, handle load, and prepare the received data for React applications.
useCustomMDMSV2
Create the hook under the following path:
Once the project structure is ready, it is time to install and configure the module dependencies in the Master Data Management Service (MDMS). Follow the steps below to finalise these.
After creating the Sample
module and its package.json
file, you need to ensure that this module is enabled in the citymodule.json
file in the MDMS (Master Data Management Service) configuration. If it is not enabled, you need to update the MDMS configuration accordingly. You need to add this module to the root tenant in your environment from your branch.
file location
for reference: citymodule.json.
For illustration here, add the following module (sample) as given below:
Register the Sample UI module in three places so that it will be available to the developer at runtime as well as at the time of deployment. Below are the three places where the module needs to be registered:
micro-ui/web/micro-ui-internals/package.json
micro-ui/web/micro-ui-internals/example/package.json
Micro-ui-internals:- Open the micro-ui-internals
package.json
file and add the following inside the scripts:
In the example/package.json, add the following line:
In the web/package.json, add the following line:
The next step is to initailise the module.js, refer here to know more about the setup
DIGIT comes with common re-usable libraries that can be imported for use in a new module. Follow the steps below to import the required components.
We are reusing certain React components from our libraries, such as InboxSearchComposer
, FormComposerV2
, SubmitCard
, CardText
, and others. Refer to the link below to learn more about these components.
Learn more about our React components
All components are available in the link below. Digit-UI-Components
The next step is to register SampleModule
in module.js
, the module's entry file. To demonstrate rendering, display "Sample Module" using a simple <div>
element within the SampleModule
component. This creates a basic screen setup for the module, which can be customized or expanded as needed.
Add the below code in the Module.js file which is already created.
Initialize the module's custom hooks, configurations, and register components using initSampleComponents()
here.
Refer to the file here: Module.js
If there is a local server running, make sure to stop it. Restart by running yarn install
followed by yarn start
at the micro-ui-internals
level.
Hurray! Now, the screen is displayed below on visiting the given URL:
Refer to the below sections for a deeper understanding
Front-end module project structure
Before starting with the Module code, ensure your local development environment is set up. You can refer to the local development setup guide link given below for detailed instructions.
Download the UI code from the link here Digit-Frontend. if not done earlier
Follow the steps given below to create the project structure.
Once you have cloned the repository from Digit-Frontend, do the following.
Go to micro-ui-internals → packages → modules
.
Create a new folder with module's name , For example (Sample).
Create a folder called src and add the components , configs, hooks and pages inside that.
The project structure should be as in the image below:
After creating the new Sample
module, we need to create a package.json
file for the module, specifying the module name, version, scripts, and required dependencies.
Refer to the file here - Package.json
The next step is to initialise the Dependency, refer here to learn more about the setup
Reusable Components
Reusable Hooks
Employee Module Setup