react-rails | Integrate React.js with Rails views | Frontend Framework library
kandi X-RAY | react-rails Summary
kandi X-RAY | react-rails Summary
Integrate React.js with Rails views and controllers, the asset pipeline, or webpacker.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Initialize a new child .
- The React Class .
- Sets the state of the current state .
- Start a new fiber .
- Recursively commit state changes .
- Parse module definition .
- Collect properties that are related to the DOM .
- Suspend part of expansion .
- Resolves a child component .
- Finish the rendering .
react-rails Key Features
react-rails Examples and Code Snippets
//= require react-server
//= require react_ujs
//= require ./components
windows.FeatureFlag = {featureA: true, featureB:false}
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require react_config.js
//= require react-server
//= require react_ujs
//= require_tree .
<
function foo() {
// do cool stuff here
}
//= require jquery
//= require jquery_ujs
//= require react
//= require react_ujs
//= require common
//= require_tree .
rails generate react:install
- app/
- assets/
- config/
- blorgh_manifest.js
- javascripts/
- blorgh/
- components/
- some_component.jsx
- application.js
- co
...
//= require rails-ujs
//= require jquery
//= require react
//= require components
//= require turbolinks
//= require_tree .
//= require react_ujs
// require react-server
//= require ./components
...
Community Discussions
Trending Discussions on react-rails
QUESTION
I'm trying to test my pagination feature with rspec/capybara. I created the articles using FactoryBot but encountered two issues. If I create the data:
- in a
before
block, the data is saved to the database and not wiped after the suite runs. - inside a scenario block and use
save_and_open_page
to see if the data shows on the screen, it doesn't show. So, I believe that the data doesn't have enough time to save.
gemfile:
...ANSWER
Answered 2022-Feb-26 at 19:38Your main issue here is out-of-order execution. You're visiting the page before creating the objects needing for your test, therefore the objects aren't visible on the rendered page (they didn't exist when the page was rendered). For most tests you won't want to be calling visit
in a before block, unless you have a series of test that all require the same test data, and visiting the same page. In this case just move the visit
into the scenario. Additionally, don't over-specify the selectors for the elements you're looking for because it will make your tests brittle. You don't show what your html looks like, but assuming this page is only showing one list of articles then checking for just one of your classes may be enough, or scoping your expectation to a page area, and then using a more general CSS selector
QUESTION
Currently, Rails application is on service.
The environment is following the below.
I'm thinking to introduce React to my app.
But in case of management screen, I want to use Rails.
Because it's already customized a lot and no complaint so far.
I think to introduce React to Rails app is 3way.
- Using Webpacker
- Using Gem(react-rails/react_on_rails)
- Using
create-react-app
From my thinking, 1&2 and 3 have big differences. 1&2 is React renders from Rails View. 3 is React renders independently and Rails is just used for API.
So I have three questions.
- Compare 1&2 and 3, which is faster? Is there big different?
- In case of 3, I think React'host should be 3000, Rails should be 3001. Is it possible to release step by step? Like introducing React only top screen, others are Rails.
- In case of 3, can I use RailsAdmin for management screen?
I have no idea.
Please help me..
ANSWER
Answered 2022-Jan-14 at 08:33I would almost always use the approach number 3, as in using Rails as an API and having admin panel. To achieve this you simply define a different route for all the api endpoints and the admin, don't overthink this. Under the rails port you can put all the API endpoints and a rails admin endpoint. Using Webpacker in rails is still supported but starting with rails 7 it is no longer the default, which means that in case of some problems (which in my experience are frequent with webpacker) you might have a harder time finding some help. Using gems to work with JS frameworks always seems to me like an unnecessary complication, and adding an extra tool to help with a different tool...
Keep both tools to themselves, you can still have both apps in one repository nothing is stoping you from that, but Rails being responsible for the backend and react being the frontend is the most sensible approach IMHO. Nothing stands in a way of using rails app as both the API server and rails admin managment view. It is just a matter of setting up the routes.
QUESTION
I git this error React::ServerRendering::PrerenderError in Search#show from this scrip
...ANSWER
Answered 2021-Nov-26 at 17:21Now I can fix the issue by update from
<%= react_component('TagList', { tags: @tags }, { prerender: true }) %>
to
<%= react_component('TagList', { tags: @tags }, { prerender: false }) %>
QUESTION
I was trying to deploy my reactjs rails app on heroku.
Everything seems okay until I get this error:
...ANSWER
Answered 2021-Sep-07 at 12:12Heroku defaults to NODE_END=production
. How does this affect your build?
You have @babel/preset-react
in devDependencies
. When you do npm i
(or yarn
) to install packages with NODE_ENV=production
, npm (or yarn) only installs dependencies
(it wont install devDependencies
).
To get around this, you can -
- either override
NODE_ENV
. ($ NODE_ENV=development npm i
) - Run
npm i --only=dev
before you build
To be on the safe side, revert the value on NODE_ENV
to production when you run in production environment (Heroku in your case).
QUESTION
I have this controller
ANSWER
Answered 2021-Aug-31 at 05:48The problem is right here:
QUESTION
Is it a good practice to store a CSRF token in redux? I was passing it with props before (to add it to Axios headers). I have a rails back end and I am using the gem react-rails
, my components are server rendered, so I did not come up with any other way of doing so but passing the CSRF token to the component.
ANSWER
Answered 2021-Jun-02 at 17:53It's fine to store the token in your Redux store.
The purpose of the token is to prevent other sites/origins from making non-GET (POST, PUT, DELETE) requests to your API. Without it, a malicious site could make the request and piggyback on the cookies and session stored in your browser. In a plain HTML server-rendered Rails app, this token is put directly into the HTML, making it available to any JavaScript on that page. So, it's not private information for any code on the pages you control.
Nonetheless, given it's global nature and that you might need it outside of the context of Redux, it's probably best to put it on window
for anyone to use:
QUESTION
While working with the react-rails
library, we can use the react_component() function in an .erb
file to add a react component.
How can we use the same function in a .haml
file? Or do we have another way of adding a react component in a haml file?
ANSWER
Answered 2021-Feb-09 at 13:26If webpacker is setup in your RoR project, then you can simply use the react_component
function from react-rails
in the same way we would add ruby code to the haml file.
Ex:
QUESTION
I'm SO frustrated. I'm literally implementing straight from the Stripe Docs, and I keep getting the error
Error: Invalid prop 'stripe' supplied to 'Elements'. We recommend using the 'loadStripe' utility from '@stripe/stripe-js'
... but I am! What is wrong with this script? I've searched everywhere, and can not find any reason why I'm getting this error.
...ANSWER
Answered 2020-Nov-15 at 11:22Please check if you have loaded the stripe script from your index.html. if so, please remove it. The method you use works for react library only and creates incompatibility if you load another Stripe library via index.html.
QUESTION
I'm running Rails 6 w/ React-Rails and using a webpack-dev-server with hot reloading for development. Most of the time everything works fine; when I save changes to my javascript files webpacker recompiles and loads the updates.
Twice now while developing I'll be in a "good" state then I'll click save and all of a sudden a new folder while be created adjacent to my file called dist
. For example, I've got a file called app/javascript/components/common/uploader/index.tsx
and when I save changes to the file, now folder app/javascript/components/common/uploader/dist
is created with the file index.js
inside of it.
My understanding is that all these sorts of files should be stored in memory when using webpack-dev-server, so surprised to see them showing up. It's also particularly odd that this starts happening without me changing any settings, just saving the same file twice changes it and reverting back to master doesn't solve the problem. The first time I got rid of it by deleting the entire root folder and then syncing back to the master on my repo but now that isn't doing the trick.
...ANSWER
Answered 2020-Oct-19 at 17:39Turns out it wasn't a webpacker problem at all, issue was with VS Code Compile Hero... Vs code create folder automatically with (dist) name
QUESTION
I am using rails 5.1.7 with the gem react-rails.
I added a react component in a erb view as:
...ANSWER
Answered 2020-Sep-29 at 06:27works fine on my local environment
Did you try precompiling locally?
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-rails
app/javascript/components/ directory for your React components
ReactRailsUJS setup in app/javascript/packs/application.js
app/javascript/packs/server_rendering.js for server-side rendering
Fix: Try updating yarn package.
While using installers.(rails webpacker:install:react && rails webpacker:install) Error:
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page