question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Card.Title expects type `React.ReactNode` but is rendered inside a `StyledText` -- which means in effect it can only accept a Text node

See original GitHub issue

Description

Per the type definitions[1], Card.Title’s title prop should accept any react node. However, because it is wrapped in a StyledText via the <Title> component[2], it can only accept text nodes. This is quite limiting for devs who want to customize their Card titles, especially since the left prop does not have style controls.

For example, in my use case: I want to put an Icon before the text of the title, at the same size as the title text, and with only a gap of 16px between the icon and the text. I have to either put the icon in the left then give the title a negative left margin (because the left has a fixed width of 40), or I have to use an icon set that renders as text glyphs so that I can include it in the title itself; passing anything that is/contains a <View> to title results in the error Invariant Violation: Nesting of <View> within <Text> is not currently supported.

The title prop of Card.Title should not be wrapped in a <Text>-based component, so that <View>-based children can be passed to it. Either that or the type definition for CardTitleProps should be updated to admit its limitation to only <Text> components.

for example, here’s the desired state: Screen Shot 2019-04-23 at 12 32 28 PM

and here’s how that looks if I don’t do the hacky negative left margin on the title: Screen Shot 2019-04-23 at 12 32 51 PM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jaulzcommented, Apr 23, 2019

Hm, maybe we should think about having a leftStyle and rightStyle then. This would be backward compatible and similar to the props we have for other components. Could you please come up with a PR which also includes the change of the type of title?

0reactions
github-actions[bot]commented, Dec 15, 2019

Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The React.ReactNode type is a black hole - Changelog
The expected use is that this object is passed to a <T> component that knows how to use it and a library of...
Read more >
Some components "cannot be used as a JSX component"
Its instance type 'Provider<AnyAction>' is not a valid JSX element. The types returned by 'render()' are incompatible between these types. Type ...
Read more >
JSX In Depth - React
The first part of a JSX tag determines the type of the React element. Capitalized types indicate that the JSX tag is referring...
Read more >
Adding A Commenting System To A WYSIWYG Editor
StyledText will check if the text node it's trying to render has any comments on it. If it does, it renders CommentedText ....
Read more >
Props! — and how to pass props to components in React ...
Normally you start out with React's JSX syntax for rendering something to the browser when learning about React. Basically, JSX mixes HTML with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found