Skip to content

Commit 3de1c4c

Browse files
committed
Add example JavaScript
1 parent 26538e0 commit 3de1c4c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/the-new-architecture/pillars-turbomodule.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,46 @@ Then, to manually link your new TurboModule:
657657
return rncore_ModuleProvider(moduleName, params);
658658
}
659659
```
660+
661+
### JavaScript
662+
663+
Now you can use your TurboModule calculator in your app!
664+
665+
Here's an example App.js file using the `add` method:
666+
667+
```js title="App.js"
668+
/**
669+
* Sample React Native App
670+
* https://github.com/facebook/react-native
671+
*
672+
* @format
673+
* @flow strict-local
674+
*/
675+
import React from 'react';
676+
import {useState} from 'react';
677+
import type {Node} from 'react';
678+
import {SafeAreaView, StatusBar, Text, Button} from 'react-native';
679+
import RTNCalculator from 'rtn-calculator/js/NativeCalculator.js';
680+
681+
const App: () => Node = () => {
682+
const [currentResult, setResult] = useState<number | null>(null);
683+
return (
684+
<SafeAreaView>
685+
<StatusBar barStyle={'dark-content'} />
686+
<Text style={{marginLeft: 20, marginTop: 20}}>
687+
3+7={currentResult ?? '??'}
688+
</Text>
689+
<Button
690+
title="Compute"
691+
onPress={async () => {
692+
const result = await RTNCalculator.add(3, 7);
693+
setResult(result);
694+
}}
695+
/>
696+
</SafeAreaView>
697+
);
698+
};
699+
export default App;
700+
```
701+
702+
Try this out to see your TurboModule in action!

0 commit comments

Comments
 (0)