{"id":20792619,"url":"https://github.com/mkrl/nodecg-react","last_synced_at":"2025-07-02T09:04:23.411Z","repository":{"id":44112607,"uuid":"195217146","full_name":"mkrl/nodecg-react","owner":"mkrl","description":"A NodeCG kickstart bundle, powered up by React and Parcel","archived":false,"fork":false,"pushed_at":"2022-12-09T17:02:28.000Z","size":1022,"stargazers_count":9,"open_issues_count":10,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T22:02:27.690Z","etag":null,"topics":[],"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/mkrl.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":"2019-07-04T10:01:53.000Z","updated_at":"2024-05-15T01:59:12.000Z","dependencies_parsed_at":"2023-01-25T22:45:16.583Z","dependency_job_id":null,"html_url":"https://github.com/mkrl/nodecg-react","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkrl/nodecg-react","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkrl%2Fnodecg-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkrl%2Fnodecg-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkrl%2Fnodecg-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkrl%2Fnodecg-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkrl","download_url":"https://codeload.github.com/mkrl/nodecg-react/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkrl%2Fnodecg-react/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263108803,"owners_count":23415004,"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":[],"created_at":"2024-11-17T15:53:05.186Z","updated_at":"2025-07-02T09:04:23.391Z","avatar_url":"https://github.com/mkrl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodecg-react\n\nThis is a [NodeCG](http://github.com/nodecg/nodecg) boilerplate bundle, powered by React, Parcel and a Flux-like pattern system for an easy state-to-[replicant](https://nodecg.com/NodeCG.html#Replicant) management.\n\nIt works with NodeCG versions which satisfy this [semver](https://docs.npmjs.com/getting-started/semantic-versioning) range: `^1.1.1`\n\n\n## Getting started\n\nCopy/clone the repo into your `bundles` folder that is located in the root folder of your NodeCG instance.\n```bash\ncd bundles\ngit clone git@github.com:mkrl/nodecg-react.git\ncd nodecg-react\n```\nInstall dependencies with `yarn` or `npm`\n```bash\nyarn\n# or\nnpm i\n```\n\nStart up your NodeCG instance. \n\nIn order to generate asset bundle from sources, run `npm start` at least once, as the repository does not initially come with pre-compiled assets.\n\n## Developing\n\n[Parcel](https://parceljs.org/) is a zero-configuration asset bundler. We use [Babel](https://babeljs.io/) to compile modern JavaScript with React into a single asset file that lives in our `/graphics` folder. \nIn order to get started, run \n```bash\nnpm start\n```\nThis will spin up Parcel watch mode. Open your app through a NodeCG \"graphics\" tab. You can now make desired changes to your source files under `/src` and they will automatically be hot-reloaded in your browser.\n\n## Working with replicants and component state\n\nThe main purpose of this bundle is to create a reliable bridge between replicants and React state using Flux-like store.\n\nLet's say, we have a basic class-based root component (this is exactly what this bundle comes with):\n\n```js\n...\nclass App extends React.Component {\n  constructor() {\n  super()\n    this.state = {\n      name: \"Brandon\"\n    }\n  }\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003ch1\u003eHello, {this.state.name}!\u003c/h1\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n...\n```\n\nConnecting to NodeCG replicants can then be done by importing `replicate` from our `stores/NodecgStore.js`. It is a function that takes a single argument - a replicant name.\n\nAfter subscribing to a replicant, all you need to do is listen for changes on the store. At the very end our component should look something like this:\n\n```js\n...\nimport NCGStore from './stores/NodecgStore'\nimport { replicate } from './stores/NodecgStore'\n\nclass App extends React.Component {\n  constructor() {\n  super()\n    this.state = {\n      replicants: NCGStore.getReplicants(),\n    }\n  }\n\n  componentDidMount() {\n    // Subscribing to replicant changes\n    replicate(\"name\")\n    // We keep all our subscribed replicants in a single \"replicants\" object\n    NCGStore.on(\"change\", () =\u003e {\n      this.setState({\n        replicants: NCGStore.getReplicants(),\n      })\n    })\n  }\n\n  render() {\n    return (\n\t    \u003cdiv\u003e\n        \u003ch1\u003eHello, {this.state.replicants.name}!\u003c/h1\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n\n...\n```\n\nDon't forget to define your replicants themselves, somewhere in your extension or a panel:\n```js\n// extension.js\nmodule.exports = nodecg =\u003e {\n\tconst nameReplicant = nodecg.Replicant('name', {defaultValue: \"Brandon\"})\n}\n```\n\nYour component state will now be updated automatically whenever you initiate a replicant value change.\n\nBear in mind, if you don't declare your replicants before subscribing to them with `replicate()`, their initial value will be set to `undefined`, no matter what `defaultValue` is being passed to the declaring statement.\n\n## Building\n\nEven though running in a watch mode does produce working pieces of code, you are going to need a production build after you are done with your development process. Generating optimized and minified graphics is as simple as:\n\n```bash\nnpm run build\n```\n\n## Contributing\n\nFeel free to contribute, following this conventional and simple process:\n\n 1. [Fork](https://github.com/mkrl/nodecg-react/fork)\n 2. Create your feature branch (`git checkout -b new-cool-stuff`) \n 3. Commit (`git commit -am 'Add stuff'`) \n 4. Push to the branch (`git push origin new-cool-stuff`)\n 5. Create a new Pull Request\n\nPlease note that this is still an early work-in-progress.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkrl%2Fnodecg-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkrl%2Fnodecg-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkrl%2Fnodecg-react/lists"}