Skip to content

Instantly share code, notes, and snippets.

View jdmunro's full-sized avatar

James Munro jdmunro

View GitHub Profile
@jdmunro
jdmunro / eslint.conf.js
Created September 27, 2019 14:11
Deprecation Example
"deprecate/member-expression": [
"warn",
{
"name": "React.Component",
"use": "We prefer to use Functional Components: refer to ADR #0002."
}
]
// ExerciseTopBar.web.js
// Import the props from the mobile implementation
// The actual JS will not be included in the web bundle
import type { Props } from "app/components/ExerciseTopBar.js";
// AfterWorkoutScreen.web.js
// AfterWorkoutScreen.js
import connectAfterWorkoutScreen from './connectAfterWorkoutScreen'
class AfterWorkoutScreen extends React.PureComponent {
// ...
}
// Re-use the connect call
default default connectAfterWorkoutScreen(AfterWorkoutScreen)
// connectAfterWorkoutScreen.js
export default connect(
mapStateToProps, // Map state to props for both screens
mapDispatchToProps // Map dispatch to props for both screens
);
module.exports = {
// ...
resolve: {
// ...
// Prefer .web.js over .js files
extensions: [".web.js", ".js"]
}
};
// Mobile and web only
const style = selectOnPlatform({
mobile: styles.mobileStyle,
web: styles.webStyle
});
// Alternatively, analogous to Platform.select
const style = selectOnPlatform({
android: styles.androidStyle,
ios: styles.iosStyle,
const style = Platform.select({
android: styles.mobileStyle,
ios: styles.mobileStyle,
web: styles.webStyle
});
const someJsx = (
<SomeComponent
style={Platform.select({
android: styles.androidStyle,
ios: styles.iosStyle
})}
/>
);
const marginStyle = {
marginTop: Platform.OS === "android" ? 60 : 19,
marginBottom: Platform.OS === "android" ? 60 : 0
};
import * as React from "react";
const codePush = (App: React.Node) => App;
codePush.getUpdateMetaData = () => {
return Promise.resolve(null);
};
export default codePush;