Adding styling to rails react component wrapping div
Asked Answered
C

2

8

I'm using react_component in my Rails project. This inserts a wrapping div for the react.js component, e.g.

<div data-react-class="ButtonSwitchToTab" data-react-props="{...}">
  <a href="#" class="btn btn-primary btn-lg" ... data-reactid=".2">
    Add / Invite People
  </a>
</div>

What I really need is to insert style information into this wrapping div so that components align appropriately, like so:

<div data-react-class="ButtonSwitchToTab" data-react-props="{...}"
 style="display:inline-block">  <<<<<------
  <a href="#" class="btn btn-primary btn-lg" ... data-reactid=".2">
    Add / Invite People
  </a>
</div>

What's the appropriate way to do that?

Campinas answered 26/6, 2015 at 2:25 Comment(0)
C
11

Ah, dove deeper into react_rails doco (Helper's signature) and found that I could add pass-through html_options.

So:

<%= react_component('ButtonSwitchToTab', {prop: .., prop: ..}, 
                    {:style => "display:inline-block"}) %>
Campinas answered 26/6, 2015 at 2:35 Comment(0)
K
0

I needed to style the component mount point as well, and I just assigned a custom ID to my component:

= react_component 'LoginPage', id: 'login-page-container'

(HAML template)

Kook answered 14/4, 2022 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.