javascript - React Style not working with template strings - Stack Overflow

Why is this inline style not working?My console logs: The style prop expects a mapping from style prop

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?

Share Improve this question edited Jul 24, 2018 at 14:27 Tholle 113k22 gold badges208 silver badges197 bronze badges asked Jul 24, 2018 at 14:20 cyruslkcyruslk 8693 gold badges13 silver badges29 bronze badges 2
  • 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
Add a ment  | 

3 Answers 3

Reset to default 4

If 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 };

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745345976a4623544.html

相关推荐

  • javascript - React Style not working with template strings - Stack Overflow

    Why is this inline style not working?My console logs: The style prop expects a mapping from style prop

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信