{"id":19004862,"url":"https://github.com/dhis2/app-runtime-adapter-d2","last_synced_at":"2026-04-21T09:30:37.289Z","repository":{"id":37853601,"uuid":"235363808","full_name":"dhis2/app-runtime-adapter-d2","owner":"dhis2","description":"Shim for d2 within the DHIS2 App Platform","archived":false,"fork":false,"pushed_at":"2023-07-19T17:21:45.000Z","size":3478,"stargazers_count":0,"open_issues_count":19,"forks_count":1,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-02-02T19:17:51.814Z","etag":null,"topics":["synced-settings","web-lib"],"latest_commit_sha":null,"homepage":"https://developers.dhis2.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhis2.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-21T14:38:44.000Z","updated_at":"2022-06-13T14:04:31.000Z","dependencies_parsed_at":"2024-06-21T16:45:36.349Z","dependency_job_id":null,"html_url":"https://github.com/dhis2/app-runtime-adapter-d2","commit_stats":{"total_commits":34,"total_committers":7,"mean_commits":4.857142857142857,"dds":0.7647058823529411,"last_synced_commit":"35252aba84301a49461f25f63e6b84c2f1120baa"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fapp-runtime-adapter-d2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fapp-runtime-adapter-d2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fapp-runtime-adapter-d2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhis2%2Fapp-runtime-adapter-d2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhis2","download_url":"https://codeload.github.com/dhis2/app-runtime-adapter-d2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240027432,"owners_count":19736211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["synced-settings","web-lib"],"created_at":"2024-11-08T18:24:53.806Z","updated_at":"2026-04-21T09:30:37.220Z","avatar_url":"https://github.com/dhis2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# app-runtime-adapter-d2\n\nSupport [`d2`](https://github.com/dhis2/d2) and [`d2-ui`](https://github.com/dhis2/d2-ui) components in [DHIS2 Platform](https://platform.dhis2.nu) applications\n\n## Requirements\n\nThs library has two peer dependencies:\n\n-   [`d2`](https://www.npmjs.com/package/d2)\n-   [`@dhis2/app-runtime`](https://www.npmjs.com/package/@dhis2/app-runtime)\n\n## Initializing D2\n\nThere are two entrypoints to support initialization and access to the `d2` singleton from within an application.\n\n-   `useD2`, a React Hook\n\n```js\nimport React, { useState } from 'react'\nimport { useD2 } from '@dhis2/app-runtime-adapter-d2'\nimport { getUserSettings } from 'd2'\n\nconst d2Config = {\n    schemas: ['dataElement', 'program', 'userGroup'],\n}\n\nconst MyApp = () =\u003e {\n    const [userSettings, setUserSettings] = useState(null)\n\n    const onInitialized = (d2) =\u003e {\n        getUserSettings().then(setUserSettings)\n\n        /* ... do other things with d2 ... */\n    }\n    const { d2, d2Error } = useD2({ d2Config, onInitialized })\n\n    /* ... optionally render error or loading state ... */\n\n    if (d2 \u0026\u0026 !d2Error \u0026\u0026 userSettings) {\n        /* ... render the application ... */\n    }\n}\n\nexport default MyApp\n```\n\n-   `D2Shim`, a React Component that wraps the `useD2` hook. It accepts a single child **function**\n\n```js\nimport React, { useState } from 'react'\nimport { useD2 } from '@dhis2/app-runtime-adapter-d2'\nimport { getUserSettings } from 'd2'\nimport { ScreenCover, CircularLoader } from '@dhis2/ui-core'\nimport Root from './components/Root' // This is the business logic of the application\n\nconst d2Config = {\n    schemas: ['dataElement', 'program', 'userGroup'],\n}\n\nconst onD2Initialized = async (d2) =\u003e {\n    const userSettings = await getUserSettings()\n\n    /* do something with userSettings or d2 - spawn Redux initialization actions, for instance */\n}\n\nconst MyApp = () =\u003e (\n    \u003cD2Shim d2Config={d2Config} onInitialized={onD2Initialized}\u003e\n        {({ d2, d2Error }) =\u003e (\n            \u003c\u003e\n                {d2Error \u0026\u0026 (\n                    \u003cdiv\n                        style={{\n                            display: 'flex',\n                            height: '100%',\n                            width: '100%',\n                            alignItems: 'center',\n                            justifyContent: 'center',\n                        }}\n                    \u003e\n                        {`D2 initialization error: ${d2Error}`}\n                    \u003c/div\u003e\n                )}\n                {!d2 \u0026\u0026 !d2Error \u0026\u0026 (\n                    \u003cScreenCover\u003e\n                        \u003cCircularLoader /\u003e\n                    \u003c/ScreenCover\u003e\n                )}\n                {d2 \u0026\u0026 \u003cRoot d2={d2} store={store} /\u003e}\n            \u003c/\u003e\n        )}\n    \u003c/D2Shim\u003e\n)\n\nexport default MyApp\n```\n\nBoth accept three options:\n\n-   `d2Config` - an object passed to the `init` function when initializing `d2`\n-   `onInitialized` - a callback function executed when `d2` has been initialized. It will be **await**ed, so returning a promise will delay resolution of the `d2` return value.\n-   `i18nRoot` - an optional string that indicates the app's directory containing \"legacy\" i18n files, e.g., i18n_module_en.properties. In data-visualier, for example, the string would be \"i18n_old\". When this string is set, the properties file of the current language will be loaded.\n\n## Referencing D2\n\nThe same two entrypoints can be used multiple places within an application to reference the `d2` singleton. Once `d2` has been initialized it will not be re-initialized, so you can safely call `useD2` or render `D2Shim` without any arguments further down the VDom tree after rendering `D2Shim` with initialization parameters at the application entrypoint.\n\n## Report an issue\n\nThe issue tracker can be found in [DHIS2 JIRA](https://jira.dhis2.org)\nunder the [LIBS](https://jira.dhis2.org/projects/LIBS) project.\n\nDeep links:\n\n-   [Bug](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10006\u0026components=11026)\n-   [Feature](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10300\u0026components=11026)\n-   [Task](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700\u0026issuetype=10003\u0026components=11026)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhis2%2Fapp-runtime-adapter-d2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhis2%2Fapp-runtime-adapter-d2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhis2%2Fapp-runtime-adapter-d2/lists"}