Skip to content

Instantly share code, notes, and snippets.

@steida
Created June 7, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steida/f08dcda8c17528167fb8624df7b1d04b to your computer and use it in GitHub Desktop.
Save steida/f08dcda8c17528167fb8624df7b1d04b to your computer and use it in GitHub Desktop.
Textarea auto height for server side rendering
<TextInput
multiline
// value={value}
defaultValue={value}
onChange={this.handleChange}
placeholderTextColor={placeholderTextColor}
placeholder={intl.formatMessage(messages.placeholder)}
ref={this.inputRef}
style={[
theme.styles.editorTextInput,
theme.typography.fontSizeWithLineHeight(0),
]}
id={id}
/>
{/* Set height immediately before the client JavaScript is run. */}
{/* This causes Warning: Extra attributes from the server: style */}
{/* That's annoying but fine. */}
{/* {Platform.OS === 'web' &&
!('browser' in process) && (
<script
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `
var el = document.getElementById('${id}');
el.style.height = 0;
el.style.height = el.scrollHeight + 'px';
`,
}}
/>
)} */}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment