Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save agenthunt/1cc881a6d2b04cb09aaffe727e6cb2af to your computer and use it in GitHub Desktop.
Save agenthunt/1cc881a6d2b04cb09aaffe727e6cb2af to your computer and use it in GitHub Desktop.
hello-react-native-custom-renderer-myReactNativeWebRenderer-createInstance.js
createInstance: (type, newProps, rootContainerInstance, _currentHostContext, workInProgress) => {
const domElement = document.createElement('div');
Object.keys(newProps).forEach(propName => {
const propValue = newProps[propName];
if (propName === 'children') {
if (type !== 'text') {
if (typeof propValue === 'string' || typeof propValue === 'number') {
throw new Error('Text strings must be rendered within a <Text> component.');
}
if (propValue instanceof Array) {
propValue.forEach(item => {
if (typeof item === 'string') {
throw new Error('Text strings must be rendered within a <Text> component.');
}
});
}
}
} else if (propName === 'style') {
const styleString = convertCamelCasetoInlineStyle(propValue);
domElement.setAttribute('style', styleString);
} else {
const propValue = newProps[propName];
domElement.setAttribute(propName, propValue);
}
});
return domElement;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment