<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Learn React with chantastic on Medium]]></title>
        <description><![CDATA[Stories by Learn React with chantastic on Medium]]></description>
        <link>https://medium.com/@learnreact?source=rss-6dcc678e152a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*M-pxLuwCMoMo52W1.png</url>
            <title>Stories by Learn React with chantastic on Medium</title>
            <link>https://medium.com/@learnreact?source=rss-6dcc678e152a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:15:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@learnreact/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Inline Styles for Basic Pseudo-Classes]]></title>
            <link>https://medium.com/@learnreact/inline-styles-for-basic-pseudo-classes-ee8f564792d4?source=rss-6dcc678e152a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee8f564792d4</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Learn React with chantastic]]></dc:creator>
            <pubDate>Sat, 13 Jun 2015 20:21:02 GMT</pubDate>
            <atom:updated>2015-06-13T20:26:48.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhIsVne6c5MW1P8Kh-5FqA.jpeg" /></figure><p><em>Using map() to recreate first-child and nth-child</em></p><p>My first blocker with inline-styles was <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes">pseudo-classes</a>. I make lots of lists. So, I felt pretty exposed without <em>:first-child() </em>and friends.</p><p>Let’s try recreating some of these handy selectors using <em>map()</em>.</p><h4>What’s a map()<em>?</em></h4><p>If you’re new to React, chances are you’ve already seen sample uses of <em>map()</em>. But maybe you’re not entirely sure what it does. Let’s step through it.</p><p><em>map()</em> is a function called on an array</p><pre>[1, 2, 3]<strong>.map()</strong></pre><p><em>map()</em> takes a function as an argument</p><pre>[1, 2, 3].map(<strong>function () {}</strong>);</pre><p>This function is called with each element in the array</p><pre>[1, 2, 3].map(function (<strong>n</strong>) { <strong>return n</strong> });</pre><pre>// =&gt; function (1) { return 1 }<br>// =&gt; function (2) { return 2 }<br>// =&gt; function (3) { return 3 }</pre><p>A new array is then created — and returned — with all the new values</p><pre>[1, 2, 3].map(function (n) { <strong>return n + 1</strong> });</pre><pre>// =&gt; <strong>[2, 3, 4]</strong></pre><p>Map also provides the <em>index</em> of each element</p><pre>[1, 2, 3].map(function <strong>(n, i)</strong> { /* ... */ });</pre><pre>// =&gt; function <strong>(1, 0)</strong><br>// =&gt; function <strong>(2, 1)</strong><br>// =&gt; function <strong>(3, 2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          </strong></pre><p>We’ll use this index to emulate pseudo-classes.</p><h4>The Setup</h4><p>Assume we have a <em>render</em> function like this:</p><pre>&lt;ul&gt;<br>  {this.props.items.map((item, <strong>i</strong>) =&gt; {<br>    return &lt;Item <em>highlight=</em><strong>{i === 0}</strong> item={item} /&gt;;<br>  })}<br>&lt;/ul&gt;</pre><p>Pretty common. For each <em>item</em>, we create a new <em>&lt;Item&gt;</em> component. <em>&lt;Item&gt;</em> takes <em>highlight </em>as a <em>prop</em> and applies styles accordingly.</p><p>I want to focus on the expression needed to get <em>&lt;Item&gt;</em> highlighting the right elements:</p><pre><strong>{i === 0}</strong></pre><p><strong><em>:first-child </em></strong>targets the first element in a list. In an array, this is <em>index 0</em></p><pre>i === 0</pre><p><strong><em>:nth-child(5) </em></strong>targets the fifth element in a list. In an array, this is <em>index 4</em></p><pre>i === 4</pre><p><strong><em>:nth-child(even)</em></strong><em> </em>targets <strong>visually even</strong> elements in a list. In an array, these are elements at <em>odd indexes. (i % 2) </em>evaluates<em> truthy</em> for <em>odd</em> indexes<em>, </em>targeting <strong>visually even</strong> elements</p><pre>i % 2</pre><p><strong><em>:nth-child(odd)</em></strong><em> </em>targets <strong>visually odd</strong> elements in a list. In an array, these are elements it<em> even indexes. !(i % 2) </em>evaluates<em> truthy </em>for even indexs<em>, </em>targeting<em> </em><strong>visually odd </strong>elements</p><pre>!(i % 2)</pre><p>When using <em>map()</em> to target elements, you have to change your thinking from 1<em>-based </em>selectors to <em>0-based</em> arrays. This can be tricky at first. Stick with it.</p><p>Celebrate your victory by styling some lists! This is just four of the available <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes">pseudo-classes</a>. If you’re feeling adventurous, try your hand at a few of the others.</p><p>Carry on nerds.</p><p><a href="http://twitter.com/chantastic">chantastic</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee8f564792d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React on Rails: rails-assets]]></title>
            <link>https://medium.com/@learnreact/react-on-rails-rails-assets-2acd287581db?source=rss-6dcc678e152a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2acd287581db</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Learn React with chantastic]]></dc:creator>
            <pubDate>Thu, 04 Jun 2015 15:16:12 GMT</pubDate>
            <atom:updated>2016-08-21T03:23:09.762Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part two in a short series on using React with Rails.</em></p><p><a href="https://rails-assets.org/">rails-assets.org</a> an easy way to add JavaScript libraries to Rails apps. It’s built on the Bower package manager and allows you to add dependencies right inside your Gemfile. This is how you use it:</p><h4>In your Gemfile</h4><p>Add a rails-assets as a source:</p><pre>source &#39;https://rails-assets.org&#39; do<br>  # ...<br>end</pre><p>Find the library you’re looking for on <a href="https://rails-assets.org/">https://rails-assets.org/</a>. I’m bundling in <em>bootstrap</em>:</p><pre>source &#39;https://rails-assets.org&#39; do<br>  gem &#39;rails-assets-bootstrap&#39;<br>end</pre><p>Run bundle as usual.</p><pre>$ bundle install</pre><h4>In your asset files</h4><p>By default Rails generates two <a href="http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives">asset manifests</a> for you: <em>application.js</em> and <em>application.css. </em>These files use Sprockets to require application and vendor assets.</p><p>Use sprockets to require <em>bootstrap</em> globally in your js and css manifests.</p><p><em>application.js</em></p><pre>//= require bootstrap</pre><p><em>application.css</em></p><pre>/*= require bootstrap */</pre><p>Now you’re in business!</p><h4>How this works</h4><p><em>rails-assets</em> grabs JavaScript packages from Bower, analyzes their <em>package.json</em>, and serves them as honest-to-goodness gems. It’s magical.</p><h4>Why this is neat</h4><p><em>rails-assets</em> allows you to get your frontend assets directly from authors, avoiding third-party wrapper gems, which can be poorly maintained.</p><h4>What does this have to do with React?</h4><p><a href="http://alt.js.org/">Alt</a> (a popular Flux implementation) is a React library on Bower. <a href="http://rackt.github.io/react-router/">react-router</a> and <a href="http://gaearon.github.io/react-dnd/">react-dnd</a><em> </em>are also on Bower. There are hundreds of components and libraries available on Bower. <a href="http://rails-assets.org">rails-assets.org</a>, makes them instantly available to your Rails apps.</p><h4>rails-assets isn’t a module system</h4><p>This is a solution for pragmatic Rails developers that want to stay squarely on the golden path. <em>rails-assets</em>’ biggest benefit is that it works within the Rails Asset Pipeline.</p><p>In future posts we’ll take a look at some less “rails-y” solutions that get you those sweet, sweet JS-modules.</p><p>Carry on, nerds.</p><p><a href="https://twitter.com/chantastic">chantastic</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2acd287581db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[context]]></title>
            <link>https://medium.com/@learnreact/context-f932a9abab0e?source=rss-6dcc678e152a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f932a9abab0e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Learn React with chantastic]]></dc:creator>
            <pubDate>Fri, 22 May 2015 16:49:08 GMT</pubDate>
            <atom:updated>2015-09-23T12:50:26.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9grXG6lRUvYNd6OfMsIxVw.jpeg" /></figure><p><em>Context is an undocumented feature in React. I’ll talk about how it works in v0.13.</em></p><h3>environment</h3><p>Here’s an example of context. When I drop my son off at his grandparents, I remind him:</p><blockquote>Grandma hates the word ‘shit.’ Be careful not to say it.</blockquote><p>There’s a context in which my son uses more appropriate language for his environment. That context is grandma’s house. Does he say “shit?” Yup. Does he say it at grandma’s house? Nope.</p><h3>warning</h3><blockquote>There’s a bunch of use cases where context is valid. The one where it’s not, is to save you typing... — <a href="https://youtu.be/EPpkboSKvPI?t=808"><strong>Sebastian Markbåge at React.js Conf 2014</strong></a></blockquote><h3>using context, today</h3><p>context is implemented in three parts: <em>getChildContext </em>and<em> childContextTypes, </em>on the initiating component, and <em>contextTypes </em>on the child components.</p><h4>getChildContext</h4><p>In the component that initiates context, you’ll implement <em>getChildContext</em>:</p><pre>class Chan extends React.Component {<br>  getChildContext() {<br>    return {<br>      environment: &quot;grandma&#39;s house&quot;<br>    }<br>  }<br>}</pre><h4>childContextTypes</h4><p>You’ll also use <em>childContextTypes</em> to set the context type for interested children.</p><pre>Chan.childContextTypes = {<br>  environment: React.PropTypes.string<br>};</pre><h4>contextTypes</h4><p>Now our children may observe this context and behave accordingly.</p><pre>class ChildChan extends React.Component {<br>  render() {<br>    if (this.context.environment === &quot;grandma&#39;s house&quot;) {<br>      return &lt;span&gt;poop&lt;/span&gt;;<br>    }<br>    return &lt;strong&gt;shit&lt;/strong&gt;;<br>  }<br>}</pre><pre>ChildChan.contextTypes = {<br>  environment: React.PropTypes.string<br>};</pre><h3>Don’t use context</h3><p>As a general rule, don’t reach for context. I don’t use context much. I’ve used it for media queries and railsEnv.</p><p>Most of the time, you should use props.</p><p>I like to think of context the way I think of media queries. My app should run correctly without context. But context can be used to provide a more appropriate experience — “poop” vs “shit”.</p><p>Carry on, nerds.</p><p><em>Further reading: </em><a href="https://github.com/facebook/react/blob/v0.13.3/src/core/__tests__/ReactCompositeComponent-test.js#L548"><em>context unit tests</em></a></p><p><em>It should be noted that library code is a completely different thing. If your a library writer, context may be a good way of communicating library data between components without burdening end-developers.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f932a9abab0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React on Rails: react-rails gem]]></title>
            <link>https://medium.com/@learnreact/react-on-rails-react-rails-gem-970507d7a737?source=rss-6dcc678e152a------2</link>
            <guid isPermaLink="false">https://medium.com/p/970507d7a737</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Learn React with chantastic]]></dc:creator>
            <pubDate>Fri, 20 Mar 2015 17:36:35 GMT</pubDate>
            <atom:updated>2015-04-17T18:27:21.787Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part one in a short series on using React with Rails.</em></p><p>The <a href="https://github.com/reactjs/react-rails">react-rails gem</a> is a like shiny, red, ‘Easy’ button for getting React.js working on Rails. This is how to get started.</p><h3>The setup</h3><p><em>1. Add this to your Gemfile:</em></p><pre>gem &#39;react-rails&#39;, github: &#39;reactjs/react-rails&#39;</pre><p>This looks a little funky because you’re bundling in the github version directly. Life on the bleeding edge, and all. Once 1.0 gets released you’ll be able to drop the suffix.</p><p>Run `bundle` in the root of your application.</p><p><em>2. Run the install script:</em></p><pre>rails g react:install</pre><p>This does a few nifty things:</p><ul><li>Creates a <em>/components</em> directory for components</li><li>Creates a <em>components.js</em> manifest, requiring the <em>/components</em> directory</li><li>Adds <em>react.js</em>, <em>react-ujs.js</em>, and <em>components.js</em> to your <em>application.js</em> manifest</li></ul><h3>Writing a component</h3><p>Now you’re geared up to write a component. Let’s create it in our freshly minted /components directory.</p><pre>// app/assets/javascripts/components/greeting.js.jsx</pre><pre>var Greeting = React.createClass({<br>  render: function () {<br>    return &lt;h1&gt;Hi {this.props.name}!&lt;/h1&gt;;<br>  }<br>});</pre><p>The <em>.js.jsx</em> suffix tells Rails “Here be JSX. Sort that out before you do the JavaScript thing.”</p><p>Save that puppy and you’re ready to go.</p><h3>Adding components to a views</h3><p><em>react-rails</em> comes with a handy little helper for adding components to rails views. It’s called <em>react_component</em>. It’s takes two arguments*:</p><ul><li>a<em> </em><strong>component name</strong></li><li>a <strong>props</strong><em> </em>hash</li></ul><pre>&lt;%= react_component(&#39;HelloMessage&#39;, { name: &#39;Bob&#39; }) %&gt;</pre><p>This helper takes advantage of <em>react-ujs</em> to appropriately mount and unmount components when pages loads.</p><h3>What about CoffeeScript?</h3><p>Both ES6 Harmony and CoffeeScript are supported. ES6 Harmony requires <a href="https://github.com/reactjs/react-rails#jsx">additional configuration</a> and CoffeeScript has <a href="https://github.com/reactjs/react-rails#jsx">JSX-concerns</a> that need to be worked around. Be sure to <a href="https://github.com/reactjs/react-rails">consult the documentation</a>.</p><h3>Next Steps</h3><p>Now that you’re setup with <em>react-rails</em>, you might be wondering if there are other react libraries you should be using.</p><p>Next up, we’ll take a look <a href="https://rails-assets.org/">rails-assets</a> and how to bundle JavaScript libraries, assets, and components into your Rails apps.</p><p><em>All examples may be found here: </em><a href="https://github.com/learnreact/react-on-rails/tree/react-rails">https://github.com/learnreact/react-on-rails/tree/react-rails</a></p><p><em>* There’s an optional third argument that allows you to specify the tag_name used by the helper. `div` is used by default</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=970507d7a737" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Container Components]]></title>
            <link>https://medium.com/@learnreact/container-components-c0e67432e005?source=rss-6dcc678e152a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e67432e005</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Learn React with chantastic]]></dc:creator>
            <pubDate>Sat, 07 Mar 2015 21:17:06 GMT</pubDate>
            <atom:updated>2017-04-10T23:09:18.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DnYaPy28FmfMQSe4KWvyJw.jpeg" /></figure><p>One React pattern that’s had the impact on my code is the <em>container component</em> pattern.</p><p>In Jason Bonta talk High Performance Components, there’s <a href="https://www.youtube.com/watch?v=KYzlpRvWZ6c&amp;t=1351">this little gem about container components</a>.</p><p>The idea is simple:</p><blockquote>A container does data fetching and then renders its corresponding sub-component. That’s it.</blockquote><p>“Corresponding” meaning a component that shares the same name:</p><pre>StockWidgetContainer =&gt; <strong>StockWidget</strong><br>TagCloudContainer =&gt; <strong>TagCloud</strong><br>PartyPooperListContainer =&gt; <strong>PartyPooperList</strong></pre><p>You get the idea.</p><h3>Why containers?</h3><p>Say you have a component that displays comments. You didn’t know about <em>container components</em>. So, you put everything in one place:</p><pre>class <strong>CommentList</strong> extends React.Component {<br>  this.state = { comments: [] };<br><br>  componentDidMount() {<br>    fetchSomeComments(comments =&gt;<br>      this.setState({ comments: comments }));<br>  }</pre><pre>  render() {<br>    return (<br>      &lt;ul&gt;<br>        {this.state.comments.map(c =&gt; (<br>          &lt;li&gt;{c.body}—{c.author}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    );<br>  }<br>}</pre><p>Your component is responsible for both fetching data and presenting it. There’s nothing “wrong” with this but you miss out on a few benefits of React.</p><h4>Reusability</h4><p><strong>CommentList</strong> can’t be reused unless under the exact same circumstances.</p><h4>Data structure</h4><p>Your markup components should state expectations of the data they require. <a href="http://facebook.github.io/react/docs/reusable-components.html">PropTypes</a> are great for this.</p><p>Our component is opinionated about data structure but has no way of expressing those opinions. This component will break silently if the json endpoint change.</p><h3>Once again. This time with a container</h3><p>First, lets pull out data-fetching into a <em>container component.</em></p><pre>class <strong>CommentListContainer</strong> extends React.Component {<br>  state = { comments: [] };</pre><pre>  componentDidMount() {<br>    fetchSomeComments(comments =&gt;<br>      this.setState({ comments: comments }));<br>  }</pre><pre>  render() {<br>    return &lt;<strong>CommentList</strong> comments={this.state.comments} /&gt;;<br>  }<br>}</pre><p>Now, let’s rework CommentList to take <strong>comments</strong> as a prop.</p><pre>const <strong>CommentList</strong> = props =&gt;<br>  &lt;ul&gt;<br>    {props.comments.map(c =&gt; (<br>      &lt;li&gt;{c.body}—{c.author}&lt;/li&gt;<br>    ))}<br>  &lt;/ul&gt;</pre><p><a href="http://codepen.io/chantastic/pen/Qpeevw?editors=0010"><em>Example Codepen</em></a></p><h3>So, what did we get?</h3><p>We actually got a lot…</p><p>We’ve separated our <strong>data-fetching</strong> and <strong>rendering</strong> concerns.</p><p>We’ve made our CommentList component <strong>reusable</strong>.</p><p>We’ve given CommentList the ability to set <strong>PropTypes</strong> and fail loudly.</p><p>I’m a big fan of container components. They’re stepping up my React game a lot and making my components easier to read. Give them a try and <a href="https://www.youtube.com/watch?v=KYzlpRvWZ6c">watch Jason’s talk</a>. It’s excellent!</p><p>Carry on, nerds.</p><p><em>Check out </em><a href="https://learnreact.com/"><em>learnreact.com</em></a><em> for more references and tutorials.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e67432e005" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>