Skip to main content
Version: 1.0.108

Custom module

You can create your own module according to your needs and use it from moduleParams from any method.

Here is a simple example to create a simple custom module called Addition that takes two numbers and add them.

Addition.js
class Addition {
constructor() {}
add(num1, num2) {
return num1 + num2
}
}

var addition = null;

const getAddition = () => {
if (addition == null) {
addition = new Addition();
}
return addition;
};

export default getAddition;

And include the Addition in RNNano componenent like below

import {RNNano} from  'react-native-nano';
import Addition from 'Addition'

const customModules =  {
"addition" : Addition
}


const App = () => {
return <RNNano screens={[screen]} customModules={customModules} />;
};
export default App;

And use the addition module from any method like below.

const buttonPress = {
component: NANO.BUTTON,
value: 'CLICK ME TO ADD',
onPress: ({ moduleParams }) => {
const added = moduleParams["addition"].add(1, 2)
console.log(added)
}
};

const screen = {
name: 'HomeScreen',
screen: {
h1: [buttonPress],
}
};