Editmode Docs
Search…
Editmode for React Native
Editmode is a CMS for your mobile app copy.

Installation

Use npm to install Editmode:
1
npm install editmode-react-native
Copied!

Usage

Step 1: Import the Editmode wrapper and wrap your App within it

1
import { Editmode } from "editmode-react-native";
2
export default function App() {
3
return (
4
<Editmode projectId={project_id}>
5
<App />
6
</Editmode>
7
)
8
}
9
);
Copied!

Step 1a (Optional): Create an Editmode account on Editmode.com and create/import your content

πŸ‘‰ Editmode Sign Up πŸ‘ˆ

Rendering content inside your app

In order to render app copy, you'll need to wrap it in the <Chunk /> component.
The most basic way to render content is to pass in the identifier of your chunk on the Editmode platform.
1
import { Chunk } from "editmode-react-native";
2
​
3
function Example() {
4
return (
5
<section>
6
<Chunk identifier="cnk_b6d6754b2cf6c59a7847" />
7
</section>
8
);
9
}
Copied!
For better readability, you can opt to pass in the content key of your chunk on the Editmode platform.
1
import { Chunk } from "editmode-react-native";
2
​
3
function Example() {
4
return (
5
<section>
6
<Chunk contentKey="simple_chunk_example" />
7
</section>
8
);
9
}
Copied!
Use variables to personalize and interpolate the content you're showing.
1
import { Chunk } from "editmode-react-native";
2
​
3
function Example() {
4
return (
5
<section>
6
<Chunk contentKey="welcome_message" variables={{first_name:"Joe"}} />
7
</section>
8
);
9
}
Copied!

Fallbacks

As you may have inferred, the above examples rely on the Editmode API to serve content. This carries speed and uptime considerations. To address this, you may also specify your own fallback content, in a number of ways.

Using a resource file

1
import { defaultChunks } from "./data/defaultChunks";
2
import { Chunk } from "editmode-react-native";
3
​
4
function Example() {
5
return (
6
<Editmode projectId={project_id} defaultChunks={defaultChunks} >
7
<section>
8
{/* The following chunk will first check the content in defaultChunks before hitting the API. */}
9
<Chunk identifier="cnk_b6d6754b2cf6c59a7847" />
10
</section>
11
</Editmode>
12
);
13
}
Copied!
Want to automate your tooling or workflow and generate your resource file programatically? You can use the content returned from the GET Chunks API endpoint.

Specifying default content inline

1
import { Chunk } from "editmode-react-native";
2
​
3
function Example() {
4
return (
5
<section>
6
{/* The following chunk show the inline content before fetching content from our API. */}
7
<Chunk contentKey="welcome_message">Welcome to our app!</Chunk>
8
</section>
9
);
10
}
Copied!
Adding custom width and height to images
By default every image rendered using Editmode is sized 50px in height and 50px in width. You can override those sizes by passing imageHeight and imageWidth as props.
1
function Example() {
2
return (
3
<section>
4
<Editmode projectId="prj_h3Gk3gFVMXbl">
5
<Chunk identifier="cnk_14a3902640051246876f" imageHeight={500} imageWidth={200} />
6
</Editmode>
7
</section>
8
);
9
}
Copied!
Sizes passed through imageHeight and imageWidth are in pixels.

Trigger Cache Expire

You may want to refresh all your contents to make sure your user see the right contents in your app. You can use the refreshChunks function to force update your local storage with the recent version of your contents from Editmode Content Hub.
Example:
1
<Button
2
onPress={() => refreshChunks()}
3
title="Refresh"
4
color="#841584"
5
accessibilityLabel="Refresh"
6
/>
Copied!
Live Demo:
​View in expo​

Render Content Flow

Render Content Flow
Last modified 3mo ago