Skip to content

Commit c7e47f2

Browse files
committed
Fix link and invalid code in 'Render Functions and the Rails Context'
1 parent 95a4382 commit c7e47f2

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

docs/guides/render-functions-and-railscontext.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ For example, suppose you create a "render-function" called MyAppComponent.
2323
import React from 'react';
2424
const MyAppComponent =
2525
(props, railsContext) =>
26-
// NOTE: need to wrap in a function so this is proper React function component that can use
27-
// hooks
26+
// NOTE: need to wrap in a function so this is a proper React function component that can use hooks
2827

2928
// the props get passed again, but we ignore since we use a closure
3029
// or should we
@@ -39,7 +38,7 @@ export default MyAppComponent;
3938

4039
---
4140

42-
_This would be an alternate API where you have to call React.`createElement` and the React on Rails code doesn't do that._
41+
_This would be an alternate API where you have to call `React.createElement` and the React on Rails code doesn't do that._
4342

4443
```js
4544
import React from 'react';
@@ -60,7 +59,8 @@ export default MyAppComponent;
6059

6160
---
6261

63-
_Note: you will get a React browser console warning if you try to serverRender this since the value of `serverSide` will be different for server rendering._
62+
> [!NOTE]
63+
> You will get a React browser console warning if you try to render this on the server since the value of `serverSide` will be different for server rendering.
6464
6565
So if you register your render-function `MyAppComponent`, it will get called like:
6666

@@ -74,21 +74,23 @@ Similarly, any Redux store is always initialized with 2 parameters:
7474
reduxStore = MyReduxStore(props, railsContext);
7575
```
7676

77-
Note: you never make these calls. React on Rails makes these calls when it does either client or server rendering. You will define functions that take these 2 params and return a React component or a Redux Store. Naturally, you do not have to use second parameter of the railsContext if you do not need it. If you don't take a second parameter, then you're probably defining a React function component and you will simply return a React Element, often just JSX.
77+
> [!NOTE]
78+
> You never make these calls. React on Rails makes these calls when it does either client or server rendering. You will define functions that take these 2 params and return a React component or a Redux Store. Naturally, you do not have to use second parameter of the railsContext if you do not need it. If you don't take a second parameter, then you're probably defining a React function component and you will simply return a React Element, often just JSX.
7879
79-
(Note: see below [section](#multiple-react-components-on-a-page-with-one-store) on how to set up Redux stores that allow multiple components to talk to the same store.)
80+
> [!NOTE]
81+
> See [Redux Store](https://www.shakacode.com/react-on-rails/docs/api/redux-store-api/#multiple-react-components-on-a-page-with-one-store) on how to set up Redux stores that allow multiple components to talk to the same store.
8082
81-
The `railsContext` has: (see implementation in file [ReactOnRails::Helper](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb), method `rails_context` for the definitive list).
83+
The `railsContext` has: (see the implementation in [ReactOnRails::Helper](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb), method `rails_context` for the definitive list).
8284

8385
```ruby
8486
{
85-
railsEnv: Rails.env
87+
railsEnv: Rails.env,
8688
inMailer: in_mailer?,
8789
# Locale settings
8890
i18nLocale: I18n.locale,
8991
i18nDefaultLocale: I18n.default_locale,
9092
rorVersion: ReactOnRails::VERSION,
91-
rorPro: ReactOnRails::Utils.react_on_rails_pro?
93+
rorPro: ReactOnRails::Utils.react_on_rails_pro?,
9294

9395
# URL settings
9496
href: request.original_url,
@@ -98,10 +100,11 @@ The `railsContext` has: (see implementation in file [ReactOnRails::Helper](https
98100
port: uri.port,
99101
pathname: uri.path, # /posts
100102
search: uri.query, # id=30&limit=5
101-
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"]
103+
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"],
102104

103105
# Other
104-
serverSide: boolean # Are we being called on the server or client? Note: if you conditionally
106+
serverSide: boolean,
107+
# Are we being called on the server or client? Note: if you conditionally
105108
# render something different on the server than the client, then React will only show the
106109
# server version!
107110
}
@@ -115,7 +118,7 @@ The `railsContext` is a second param passed to your render-functions for React c
115118

116119
ERB view file:
117120

118-
```ruby
121+
```erbruby
119122
# Rails View
120123
<%= react_component("HelloWorld", props: { name: "Stranger" }) %>
121124
```
@@ -157,7 +160,7 @@ Consider this line in depth:
157160
<AppComponent {...{ ...props, railsContext }} />
158161
```
159162

160-
The outer `{...` is for the [JSX spread operator for attributes](https://facebook.github.io/react/docs/jsx-in-depth.html#spread-attributes) and the inner `{...` is for the [Spread in object literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator#Spread_in_object_literals).
163+
The outer `{...` is for the [JSX spread operator for attributes](https://legacy.reactjs.org/docs/jsx-in-depth.html#spread-attributes) and the inner `{...` is for the [Spread in object literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator#Spread_in_object_literals).
161164

162165
## Use Cases
163166

@@ -173,7 +176,7 @@ Suppose you want to display a nav bar with the current navigation link highlight
173176

174177
Suppose you want to turn off animation when doing server side rendering. The `serverSide` value is just what you need.
175178

176-
## Customization of the rails_context
179+
## Customization of the Rails context
177180

178181
You can customize the values passed in the `railsContext` in your `config/initializers/react_on_rails.rb`. Here's how.
179182

@@ -201,4 +204,4 @@ module RenderingExtension
201204
end
202205
```
203206

204-
In this case, a prop and value for `somethingUseful` will go into the railsContext passed to all react_component and redux_store calls. You may set any values available in the view rendering context.
207+
In this case, a prop and value for `somethingUseful` will go into the `railsContext` passed to all `react_component` and `redux_store` calls. You may set any values available in the view rendering context.

0 commit comments

Comments
 (0)