Skip to content

Commit

Permalink
Add example JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
lindboe committed Jun 20, 2022
1 parent ac41d2c commit b733219
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/the-new-architecture/pillars-turbomodule.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,46 @@ Then, to manually link your new TurboModule:
return rncore_ModuleProvider(moduleName, params);
}
```
### JavaScript
Now you can use your TurboModule calculator in your app!
Here's an example App.js file using the `add` method:
```js title="App.js"
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import {useState} from 'react';
import type {Node} from 'react';
import {SafeAreaView, StatusBar, Text, Button} from 'react-native';
import RTNCalculator from 'rtn-calculator/js/NativeCalculator.js';

const App: () => Node = () => {
const [currentResult, setResult] = useState<number | null>(null);
return (
<SafeAreaView>
<StatusBar barStyle={'dark-content'} />
<Text style={{marginLeft: 20, marginTop: 20}}>
3+7={currentResult ?? '??'}
</Text>
<Button
title="Compute"
onPress={async () => {
const result = await RTNCalculator.add(3, 7);
setResult(result);
}}
/>
</SafeAreaView>
);
};
export default App;
```
Try this out to see your TurboModule in action!

0 comments on commit b733219

Please sign in to comment.