{"id":15636549,"url":"https://github.com/ctrlplusb/react-async-bootstrapper","last_synced_at":"2025-04-13T01:26:48.845Z","repository":{"id":18713270,"uuid":"84932958","full_name":"ctrlplusb/react-async-bootstrapper","owner":"ctrlplusb","description":"Execute a bootstrap method on your React/Preact components. Useful for data prefetching and other activities.","archived":false,"fork":false,"pushed_at":"2022-12-07T09:16:21.000Z","size":1134,"stargazers_count":117,"open_issues_count":28,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T09:26:57.217Z","etag":null,"topics":["prefetch","react","react-dom","server-side-rendering","ssr"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctrlplusb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-14T09:54:43.000Z","updated_at":"2024-07-08T08:39:37.000Z","dependencies_parsed_at":"2023-01-13T19:58:31.002Z","dependency_job_id":null,"html_url":"https://github.com/ctrlplusb/react-async-bootstrapper","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Freact-async-bootstrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Freact-async-bootstrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Freact-async-bootstrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrlplusb%2Freact-async-bootstrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctrlplusb","download_url":"https://codeload.github.com/ctrlplusb/react-async-bootstrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248652381,"owners_count":21140000,"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":["prefetch","react","react-dom","server-side-rendering","ssr"],"created_at":"2024-10-03T11:04:57.398Z","updated_at":"2025-04-13T01:26:48.812Z","avatar_url":"https://github.com/ctrlplusb.png","language":"JavaScript","readme":"# react-async-bootstrapper 👢\n\nExecute a `bootstrap` method on your React/Preact components. Useful for data prefetching and other activities.\n\n[![npm](https://img.shields.io/npm/v/react-async-bootstrapper.svg?style=flat-square)](http://npm.im/react-async-bootstrapper)\n[![MIT License](https://img.shields.io/npm/l/react-async-bootstrapper.svg?style=flat-square)](http://opensource.org/licenses/MIT)\n[![Travis](https://img.shields.io/travis/ctrlplusb/react-async-bootstrapper.svg?style=flat-square)](https://travis-ci.org/ctrlplusb/react-async-bootstrapper)\n[![Codecov](https://img.shields.io/codecov/c/github/ctrlplusb/react-async-bootstrapper.svg?style=flat-square)](https://codecov.io/github/ctrlplusb/react-async-bootstrapper)\n\n## TOCs\n\n* [Introduction](#introduction)\n* [Simple Example](#simple-example)\n\n## Introduction\n\nThis library is a simple implementation of [`react-tree-walker`](https://github.com/ctrlplusb/react-tree-walker), allowing you to attach a `bootstrap` method to your React/Preact \"class\" components. I would highly recommend you review `react-tree-walkers` documentation so as to gain more familiarity with what is being wrapped up by `react-bootstrapper`.\n\nI have created this implementation that responds to a `bootstrap` method to allow me to have a standard implementation that would allow for interop between multiple packages requiring a bootstrapping process. For example I have create [`react-async-component`](https://github.com/ctrlplusb/react-async-component) which provides code splitting support, and [`react-jobs`](https://github.com/ctrlplusb/react-jobs) which enables data fetching. Both packages use this library to allow for a single bootstrapping parse satisfying the needs of both.\n\n## Simple Example\n\n```jsx\nimport bootstrapper from 'react-async-bootstrapper'\n\n// Our super naive global state. Don't copy this, it's just illustrative. You'd\n// likely want to use something\nconst globalStateManager = {\n  products: {},\n}\n\nclass Product extends Component {\n  // 👇\n  bootstrap() {\n    // Fetch our product and load up our state\n    return fetch(`/api/products/${this.props.productId}`).then(response =\u003e {\n      // store in our global state\n      globalStateManager.products[this.props.productId] = response.json()\n    })\n  }\n\n  render() {\n    const product = globalStateManager.products[this.props.productId]\n    return (\n      \u003cdiv\u003e\n        {product.name} - {product.price}\n      \u003c/div\u003e\n    )\n  }\n}\n\nconst app = (\n  \u003cdiv\u003e\n    \u003ch1\u003eMy favourite product\u003c/h1\u003e\n    \u003cProduct productId={1337} /\u003e\n  \u003c/div\u003e\n)\n\n// Now for the bootstrapping/rendering process (on a client/server)\nbootstrapper(app)\n  .then(() =\u003e {\n    // Bootstrapping is complete, now when we render our application to the DOM\n    // the global products state will be populated and so our components\n    // should render immediately with the data.\n    ReactDOM.render(app, document.getElementById('app'))\n  })\n  .catch(err =\u003e console.log('Eek, error!', err))\n```\n\nYep, not a particularly useful idea in the context of executing on the front end only, but when doing server side rendering of your react application this pattern can be extremely useful.\n\n## API\n\nThe API is very simple at the moment, only exposing a single function.\n\n### **bootstrapper**\n\nThe default export of the library. The function that performs the magic.\n\n```javascript\nconst bootstrapper = require('react-async-bootstrapper')\n```\n\n_or_\n\n```javascript\nimport bootstrapper from 'react-async-bootstrapper'\n```\n\n**Paramaters**\n\n* **app** (React/Preact application/element, _required_)\n\n  The react application you wish to walk.\n\n  e.g. `\u003cdiv\u003eHello world\u003c/div\u003e`\n\n* **options** (`Object`, _optional_)\n\n  Additional options/configuration. It currently supports the following values:\n\n  * _componentWillUnmount_: Enable this to have the `componentWillUnmount` lifecycle event be executed during the bootstrapping process. Defaults to `false`. This was added as an experimental additional flag to help with applications where they have critical disposal logic being executed within the `componentWillUnmount` lifecycle event.\n\n* **context** (`Object`, _optional_)\n\n  Any context you wish to expose to your application. This will become available to the entire application and could be useful for exposing configuration to your `bootstrap` methods.\n\n  e.g. `{ myContextItem: 'foo' }`\n\n**Returns**\n\nA `Promise` that resolves when the bootstrapping has completed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrlplusb%2Freact-async-bootstrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctrlplusb%2Freact-async-bootstrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrlplusb%2Freact-async-bootstrapper/lists"}