Skip to content

Instantly share code, notes, and snippets.

@wjramos
Created April 11, 2019 00:16
Show Gist options
  • Save wjramos/1a3536473a553c640ea43aa8df1d3908 to your computer and use it in GitHub Desktop.
Save wjramos/1a3536473a553c640ea43aa8df1d3908 to your computer and use it in GitHub Desktop.
export function extractNodeText(node) {
if (typeof node === 'string') return node;
if (React.isValidElement(node)) {
const { messageKey, messagesMap } = node.props;
if (messageKey && messagesMap) {
return messagesMap[messageKey];
}
return node.innerText;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment