Skip to content

Commit b222e8e

Browse files
authored
Remove PropTypes from native-components-android.md (facebook#4191)
1 parent 788d676 commit b222e8e

File tree

2 files changed

+38
-44
lines changed

2 files changed

+38
-44
lines changed

docs/native-components-android.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ import {requireNativeComponent} from 'react-native';
196196
* - borderRadius: number
197197
* - resizeMode: 'cover' | 'contain' | 'stretch'
198198
*/
199-
module.exports = requireNativeComponent('RCTImageView');
199+
export default requireNativeComponent('RCTImageView');
200200
```
201201

202202
The `requireNativeComponent` function takes the name of the native view. Note that if your component needs to do anything more sophisticated (e.g. custom event handling), you should wrap the native component in another React component. This is illustrated in the `MyCustomView` example below.
@@ -286,31 +286,28 @@ public class ReactImageManager extends SimpleViewManager<MyCustomView> {
286286

287287
This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:
288288

289-
```tsx title="MyCustomView.tsx"
290-
class MyCustomView extends React.Component {
291-
constructor(props) {
292-
super(props);
293-
this._onChange = this._onChange.bind(this);
294-
}
295-
_onChange(event) {
296-
if (!this.props.onChangeMessage) {
297-
return;
298-
}
299-
this.props.onChangeMessage(event.nativeEvent.message);
300-
}
301-
render() {
302-
return <RCTMyCustomView {...this.props} onChange={this._onChange} />;
303-
}
304-
}
305-
MyCustomView.propTypes = {
289+
```tsx {8-11,13-17} title="MyCustomView.tsx"
290+
import {useCallback} from 'react';
291+
import {requireNativeComponent} from 'react-native';
292+
293+
const RCTMyCustomView = requireNativeComponent('RCTMyCustomView');
294+
295+
export default function MyCustomView(props: {
296+
// ...
306297
/**
307298
* Callback that is called continuously when the user is dragging the map.
308299
*/
309-
onChangeMessage: PropTypes.func,
310-
...
311-
};
300+
onChangeMessage: (message: string) => unknown;
301+
}) {
302+
const onChange = useCallback(
303+
event => {
304+
props.onChangeMessage?.(event.nativeEvent.message);
305+
},
306+
[props.onChangeMessage],
307+
);
312308

313-
const RCTMyCustomView = requireNativeComponent(`RCTMyCustomView`);
309+
return <RCTMyCustomView {...props} onChange={props.onChange} />;
310+
}
314311
```
315312

316313
## Integration with an Android Fragment example

website/versioned_docs/version-0.75/native-components-android.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ import {requireNativeComponent} from 'react-native';
196196
* - borderRadius: number
197197
* - resizeMode: 'cover' | 'contain' | 'stretch'
198198
*/
199-
module.exports = requireNativeComponent('RCTImageView');
199+
export default requireNativeComponent('RCTImageView');
200200
```
201201

202202
The `requireNativeComponent` function takes the name of the native view. Note that if your component needs to do anything more sophisticated (e.g. custom event handling), you should wrap the native component in another React component. This is illustrated in the `MyCustomView` example below.
@@ -286,31 +286,28 @@ public class ReactImageManager extends SimpleViewManager<MyCustomView> {
286286

287287
This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:
288288

289-
```tsx title="MyCustomView.tsx"
290-
class MyCustomView extends React.Component {
291-
constructor(props) {
292-
super(props);
293-
this._onChange = this._onChange.bind(this);
294-
}
295-
_onChange(event) {
296-
if (!this.props.onChangeMessage) {
297-
return;
298-
}
299-
this.props.onChangeMessage(event.nativeEvent.message);
300-
}
301-
render() {
302-
return <RCTMyCustomView {...this.props} onChange={this._onChange} />;
303-
}
304-
}
305-
MyCustomView.propTypes = {
289+
```tsx {8-11,13-17} title="MyCustomView.tsx"
290+
import {useCallback} from 'react';
291+
import {requireNativeComponent} from 'react-native';
292+
293+
const RCTMyCustomView = requireNativeComponent('RCTMyCustomView');
294+
295+
export default function MyCustomView(props: {
296+
// ...
306297
/**
307298
* Callback that is called continuously when the user is dragging the map.
308299
*/
309-
onChangeMessage: PropTypes.func,
310-
...
311-
};
300+
onChangeMessage: (message: string) => unknown;
301+
}) {
302+
const onChange = useCallback(
303+
event => {
304+
props.onChangeMessage?.(event.nativeEvent.message);
305+
},
306+
[props.onChangeMessage],
307+
);
312308

313-
const RCTMyCustomView = requireNativeComponent(`RCTMyCustomView`);
309+
return <RCTMyCustomView {...props} onChange={props.onChange} />;
310+
}
314311
```
315312

316313
## Integration with an Android Fragment example

0 commit comments

Comments
 (0)