{"id":4347,"url":"https://github.com/i6mi6/react-native-sdr","last_synced_at":"2025-04-11T18:31:30.101Z","repository":{"id":57339893,"uuid":"140211395","full_name":"i6mi6/react-native-sdr","owner":"i6mi6","description":"Server Driven Rendering (SDR) component for React Native","archived":false,"fork":false,"pushed_at":"2018-07-18T10:51:59.000Z","size":999,"stargazers_count":89,"open_issues_count":1,"forks_count":7,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-26T02:36:27.556Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/i6mi6.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":"2018-07-09T00:03:04.000Z","updated_at":"2024-04-11T11:35:55.000Z","dependencies_parsed_at":"2022-09-10T19:50:38.922Z","dependency_job_id":null,"html_url":"https://github.com/i6mi6/react-native-sdr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i6mi6%2Freact-native-sdr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i6mi6%2Freact-native-sdr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i6mi6%2Freact-native-sdr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i6mi6%2Freact-native-sdr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i6mi6","download_url":"https://codeload.github.com/i6mi6/react-native-sdr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248458478,"owners_count":21107087,"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-01-05T20:17:09.079Z","updated_at":"2025-04-11T18:31:29.281Z","avatar_url":"https://github.com/i6mi6.png","language":"JavaScript","funding_links":[],"categories":["Components","Others"],"sub_categories":["UI"],"readme":"\n\u003cimg src=\"./media/logo.png\" width=\"250\" alt=\"My cool logo\"/\u003e\n\n# Server Driven Rendering (SDR) for React Native\n\n# Installation\n\n```javascript\n$ npm install react-native-sdr --save\n```\n\nor \n\n```javascript\n$ yarn add react-native-sdr\n```\n\n# Motivation\n\nServer Driven Rendering (SDR) is the process in which an app is told how to render a component remotely.\nThe difference between SDR and Server Side Rendering (SSR) is that in the latter the server does the actual rendering.\nImagine yourself building a social network app and you have to implement elements for the timeline.\nNormally, you would have multiple types of data (news, photo shares, announcements, etc.) and corresponding components for them. However, as time goes you will find the need to push new updates for every new type you add (or even small UI tweaks in certain components). SDR allows you to specify the template on your server and pass it on to your app in order to handle the rendering.\n\n# Usage\n\n## Autosync with server\n\nOn your Client:\n\n```jsx\nimport { Provider, SDRClient } from 'react-native-sdr';\n\nconst ApiClient = {\n  method: \"get\",\n  baseUrl: \"http://localhost:3000\",\n  sdrTypes: {\n    \"Text\": Text,\n    \"View\": View,\n    \"Image\": Image,\n    \"Button\": TouchableOpacity,\n  }\n}\n\nclass App extends React.Component {\n  render() {\n    return (\n      \u003cProvider client={ApiClient}\u003e\n        \u003cScreenOne /\u003e\n      \u003c/Provider\u003e\n    )\n  }\n}\n\nclass ScreenOne extends React.Component {\n  render() {\n    return (\n      \u003cView\u003e\n        \u003cSDRClient\n          url=\"/sdr/notifications/preview\"\n          {...otherProps}\n        /\u003e\n      \u003c/View\u003e\n    )\n  }\n}\n\n```\n\nand your (example Express) Server:\n\n```javascript\n\napp.get('/sdr/notifications/:type', (req, res) =\u003e {\n  const template = req.params.type === \"preview\" ? getPreviewTemplate() : getFullTemplate()\n  res.json(template)\n})\n\n```\n\n## Manual lifecycle handling\n\n```jsx\nimport SDRContainer from 'react-native-sdr';\n\n  getSDRTemplate() {\n    ...\n  }\n\n  getSDRTypes() {\n    ...\n  }\n\n  render() {\n    return (\n      \u003cSDRContainer\n        sdrTemplate={this.getSDRTemplate()}\n        sdrTypes={this.getSDRTypes()}\n        // ...otherProps \n        /\u003e\n    )\n  }\n```\n\n## Templates and types\n\nThe component requires **types** and a **template**. \nTypes are all elements that the component has access to (Image, View, etc.). If you want the component to be able to use them during the assembly, you must specify them beforehand. An example types object looks like this:\n\n```jsx\n {\n    \"Text\": Text,\n    \"View\": View,\n    \"Image\": Image,\n    \"Button\": TouchableOpacity,\n  }\n```\n\nThe template is what you pass from the server to the component. \nIt's used for rendering the component. It must look like this:\n\n```\n{\n  type: [Mandatory] Component type from predefined types,\n  props: [Optional] Props to pass to the component,\n  children: [Optional] Array of child objects or a string if text element\n}\n```\n\n**Template variables** are used to access props passed to the component. Example:\n\n```jsx\n// some usual props to your component\n{\n  notification: {\n    meta: {\n      title: \"Liked your comment\",\n      name: \"John Doe\"\n    }\n  }\n}\n\n// template from the server\n{\n  type: \"Text\",\n  children: \"Name: ${text::notification.meta.name}, Action: ${text::notification.meta.title}\"\n}\n```\n\nwill render\n\n```jsx\n\u003cText\u003eName: John Doe, Action: Liked your comment\u003c/Text\u003e\n```\n\nThere are multiple types of variables:\n\n| variable | description |\n| ------ | ------ |\n|prop::some.path.to.object|Retrieves the object from **this.props**|\n|function::some.path.to.function|Retrieves the function from **this.props**|\n|${text::some.path.to.text}|Retrieves the text from **this.props**|\n\n*Refer to the Example for more*\n\n# Available props:\n\n## Provider \n\n| prop | type | description |default|\n| ------ | ------ | ------ | ------ |\n|client|object|The client used for sync with the server||\n\n## SDRClient \n\n| prop | type | description |default|\n| ------ | ------ | ------ | ------ |\n|url|string|The endpoint which is expected to return a **template**||\n|renderLoading|func|Renders a loading component during sync|\u003cView\u003e\u003cActivityIndicator/\u003e\u003c/View\u003e|\n|renderError|func|Renders an error component if an error occurs during sync|\u003cView/\u003e|\n\n## SDRContainer \n\n| prop | type | description |default|\n| ------ | ------ | ------ | ------ |\n|sdrTemplate|object|The template to render||\n|sdrTypes|object|Types to choose from when rendering|{ \"View\": View }|\n|shouldComponentUpdate|function|shouldComponentUpdate|() =\u003e false|\n\n\nLicense\n----\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi6mi6%2Freact-native-sdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi6mi6%2Freact-native-sdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi6mi6%2Freact-native-sdr/lists"}