Skip to content

Instantly share code, notes, and snippets.

Rudi Yardley ryardley

View GitHub Profile
ryardley / app.jsx
Last active Mar 3, 2019
Creating new handlers every render can cause performance problems.
View app.jsx
function App() {
const [count, setCount] = useState(0);
// handler will be created on every render
const handleClick = () => {
setCount(count + 1);
return (
<SomePureComponent count={count} onClick={handleClick} />
# ./android/app/src/main/jni/
APP_STL := c++_static
# ./android/app/src/main/jni/
# Set up paths
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Debug mode
# Specify C++ flags
ryardley / build.gradle
Created Jan 5, 2019
Alter build.gradle
View build.gradle
android {
// ...
defaultConfig {
// ...
// the following configures ndk-build to build a "helloworld" module
ndk {
abiFilters "armeabi-v7a", "x86"
moduleName "helloworld"
ldLibs "log"
View build.gradle
apply plugin: ""
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
// ./android/app/src/main/java/com/cppreactnative/helloworld/
package com.cppreactnative.helloworld;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class HelloWorldModule extends ReactContextBaseJavaModule {
View RCTHelloWorld.m
// ios/ReactBridge/RCTHelloWorld.m
#import "RCTHelloWorld.h"
#import "HWHelloWorld.h"
@implementation RCTHelloWorld{
HWHelloWorld *_cppApi;
- (RCTHelloWorld *)init
self = [super init];
_cppApi = [HWHelloWorld create];
#!/usr/bin/env bash
### Configuration
# Djinni IDL file location
# C++ namespace for generated src
# Objective-C class name prefix for generated src
# Java package name for generated src
View helloworld.idl
hello_world = interface +c {
static create(): hello_world;
get_hello_world(): string;
View hello_world_impl.cpp
#include "hello_world_impl.hpp"
#include <string>
namespace helloworld {
std::shared_ptr<HelloWorld> HelloWorld::create() {
return std::make_shared<HelloWorldImpl>();
HelloWorldImpl::HelloWorldImpl() {
You can’t perform that action at this time.