React: Possibility to return pure text from render() without wrapping it in an element

Created on 26 Jul 2016  路  5Comments  路  Source: facebook/react

I'm asking if, in the light of #5753, it would be possible to also return plain text from render() as an alternative to the current ReactElement return type such that one would not have to wrap it in an element. Could the same comment-wrapping method allow for this also for render methods?

// Before
return <span>{this.props.text}</span>;
// After
return this.props.text;

Motivation is that it is sometimes hard to get layout to work as expected if one has to introduce span elements, and the alternative is to write plain functions instead of react components to produce the expected result. It would be syntactically nice to be able to componentize text-only components the same way as "html-enabled" components.

Most helpful comment

FWIW this is already implemented in Fiber (#6170).
We won't be bringing this to the old reconciler.

All 5 comments

I think this is convenient. and the code look like simplify.

@xkr47 Not disagreeing. But be mindful of overusing text-only components, components have non-trivial overhead and could have significant performance impact if overused.

@syranide true.. are there any benchmark results on these kinds of things? inline vs function call vs stateless component vs stateful component..?

FWIW this is already implemented in Fiber (#6170).
We won't be bringing this to the old reconciler.

Closing this since it's already implemented in the next major and it won't be added to any 15.5 release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jvorcak picture jvorcak  路  3Comments

trusktr picture trusktr  路  3Comments

zpao picture zpao  路  3Comments

framerate picture framerate  路  3Comments

UnbearableBear picture UnbearableBear  路  3Comments