

TIL: mounting stand-alone react client as a react_component in react-rails :rail...
source link: https://www.tuicool.com/articles/hit/M7JzeaN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

#+COMMENT -*- time-stamp-line-limit: 12; time-stamp-count: 2 -*-
TIL: mounting stand-alone react client as a react_component in react-rails
- last updated: Time-stamp: <2019-04-05 00:59:22 tamara>
- capture date: [2019-04-05 Fri 00:40]
- keywords: react-rails, rails, react
This should have been obvious, but for some reason seemed like it was the “wrong” way to do this.
We have a product that we’re converting slowly to react-based components. One of the central philosophies has been to build towards a standalone react client, and move the rails app to be more strictly an API provider.
I started out using the standard ReactDom
style of mounting the application to the page. This has worked well so far, until we ran into a strange issue.
The library styled-components
has been something we’ve adopted for putting our CSS in JS. However it has a problem: if multiple copies are loaded on the page in different bundles, it gets confused and the styles seem to go missing.
My first reaction was to remove all the styled-components
and go with inline style objects instead.
However, my colleague pointed out that we could also just build one bundle which would keep the issue at bay.
I ran an experiment to do this, and it worked. The essential parts are:
-
Create a new component, in my case I named it
ReactClient
, in theapp/javascript/components/
directory.-
the component essentially just imports the
App
and renders it.
-
the component essentially just imports the
-
Change the layout where you’re loading the app to instead issue and ERB call to
react_component
that callsReactClient
, possibly adding props options and HTML options. -
Remove the
webpacker
packs the build the client.
This worked really well, with the caveat that the application bundle is rather large since it now contains everything.
Recommend
-
57
USB PD Stand-alone Sink Controller Since USB-C’s introduction, I’ve been consistently interested in leveraging it for powering everything under 100 watt (or rather under 90 watt, since it’s ha...
-
9
Datascript and Quiescent TodoMVC stand-alone01 May 2014 Yesterday I wrote about clj-crud and its
-
8
Sample App : MXNA Stand-alone viewer Thursday, April 29, 2004 I recently moved moved offices, and am now sitting with the Flash team. One thing I noticed was that we have a nice 42″ Plasma screens, which was not being used....
-
7
Using HCI Mesh with a stand-alone vSphere host? Duncan Epping · Apr 13, 2021 ·
-
4
So they wouldn’t just be limited to the Amazon App Store One of the biggest announcements concerning Windows 11 is the official support for Android apps, which means users would be able to run apps...
-
8
News Ditching the PC: ADLINK Creates Stand-alone Data Acquisition System for IIOT 2 days ago by Jake Hertz Data acquisition is...
-
8
The poor UX of the browser console means many opportunities for stand-alone productivity apps Interesting observation: Makers are abstracting out individual features of the Chrome browser console and enhancing...
-
5
This is a mirror of bpf-next Linux source tree's tools/lib/bpf directory plus its supporting header files. All the gory details of syncing...
-
9
TutorialHow To Install Hadoop in Stand-Alone Mode on Ubuntu 20.04Big DataClustering
-
5
Datascript and Quiescent TodoMVC stand-alone01 May 2014 Yesterday I wrote about clj-crud and its
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK