Skip to content

Commit b733219

Browse files
committed
Add example JavaScript
1 parent ac41d2c commit b733219

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

0 commit comments

Comments
 (0)