admin管理员组文章数量:1420918
Why is this inline style
not working?
My console logs: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.
Is it because template literals converts everything into strings?
Why is this inline style
not working?
My console logs: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.
Is it because template literals converts everything into strings?
-
2
Please include your code in text form instead of an image.
style
takes an object, not a string. – Tholle Commented Jul 24, 2018 at 14:22 - It's even worth editing your question to remove the image of text. Code is text; post text. – Dave Newton Commented Jul 24, 2018 at 16:13
3 Answers
Reset to default 4If you are using Template string, you can use like this
style={{ right: `${triggerNode.right+ 50}px`, left: `${triggerNode.left}px` }}
The style
prop takes an object, so you want either { right: 0 }
or { left: 0 }
. You could solve this by using a puted property name
instead of a template string:
const randomLeftOrRight = { [returnRandom()]: 0 };
const randomLeftOrRight = { [returnRandom()] : 0 };
本文标签: javascriptReact Style not working with template stringsStack Overflow
版权声明:本文标题:javascript - React Style not working with template strings - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745345975a2654479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论