React with Rails 5.1 Calling Database Objects into React Components

Viewed 872

How do you call a Rails 5.1 database object into a React component?

For example, in a standard Rails view, I can call an object using @object assuming I have access to it configured in the controller.

With Rails 5.1, using the Webpacker enabled React functionality, how do I call a Rails database object into a React component?

I want to map through all the @objects in my database in a React component.

With the react-rails gem, you can use something like this to access those objects in your jsx file:

 <%= react_component('Component', props: @objects) %>

How do I do something similar without using the gem and just using the base Rails 5.1/Webpacker React setup?

My understanding is it uses a ruby tag like this:

<%= javascript_pack_tag "Component" %>
1 Answers
Related