class Parent extends React.Component {
constructor(props) {
super(props)
this.handler = this.handler.bind(this)
}
handler() {
this.setState({
someVar: 'some value'
})
}
render() {
return <Child handler = {this.handler} />
}
}
class Child extends React.Component {
render() {
return <Button onClick = {this.props.handler}/ >
}
}
Category: native
how to run react native app
npm install -g react-native-cli
//cd to the file where your react native projects will be
react-native init albums
// Run instructions for IOS/Android
cd projects/albums
npx react-native run-ios
npx react-native run-android
react-native run-android
react-native run-ios
npm install -g react-native-cli
npx react-native init AwesomeProject
react-native start
$ npx react-native init firstapp
how to run a cloned react native project
"dependencies": {
"react-native": "myName/react-native#release/my-react-native-release"
}
sdk.dir=/Users/your_unix_name/android-sdk-macosx
ndk.dir=/Users/your_unix_name/android-ndk/android-ndk-r17c
git checkout -d release/my-react-native-release
docker run --rm --name rn-build -v $PWD:/pwd -w /pwd reactnativecommunity/react-native-android /bin/sh -c "./gradlew installArchives"
git add android --force
git commit -a -m 'my react native forked release'
git push
npm install --save github:facebook/react-native#master
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "/path/to/build/directory/${rootProject.name}/${project.name}"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'de.undercouch:gradle-download-task:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
allprojects {
repositories { }
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
}
}
}
}
include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':ReactAndroid')
}
export ANDROID_SDK=/Users/your_unix_name/android-sdk-macosx
export ANDROID_NDK=/Users/your_unix_name/android-ndk/android-ndk-r17c
how to remove an object from array in react native
const items = ['a', 'b', 'c', 'd', 'e', 'f']
const valueToRemove = 'c'
const filteredItems = items.filter(item => item !== valueToRemove)
// ["a", "b", "d", "e", "f"]
how to reload webview in react native
You can set a key to the webview
key={this.state.key}
and then you can reload it by updating the state
this.setState({ key: this.state.key + 1 });
how to put firebase config in a sperate file react native
const firebaseApp = firebase.initializeApp(firebaseConfig);
export default firebaseApp;