<?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 jason ewins on Medium]]></title>
        <description><![CDATA[Stories by jason ewins on Medium]]></description>
        <link>https://medium.com/@jtradex?source=rss-92fbd949935e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-DzeokqRK0mISJMt5BkIfg.jpeg</url>
            <title>Stories by jason ewins on Medium</title>
            <link>https://medium.com/@jtradex?source=rss-92fbd949935e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 11:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jtradex/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[React + Cloud Firestore: Step by step tutorial]]></title>
            <link>https://medium.com/get-it-working/get-googles-firestore-working-with-react-c78f198d2364?source=rss-92fbd949935e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c78f198d2364</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[cloud-firestore]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[react-js-tutorials]]></category>
            <dc:creator><![CDATA[jason ewins]]></dc:creator>
            <pubDate>Mon, 02 Jul 2018 18:06:57 GMT</pubDate>
            <atom:updated>2019-03-26T11:54:08.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LI9TzwDU1l6IyJFBRcULw.jpeg" /></figure><p>In their own words, Firestore is Google’s flexible, scalable NoSQL cloud database to store and sync data for client- and server-side development.</p><p>So, if you’re looking to create a fully fledged app, web or native, Google’s Firestore offers a ‘path of least resistance’ route to getting up and running with a real-time database, quickly.</p><p>Great for those of us working towards an MVP and scalable for those ideas which gain traction (shouldn’t we be so lucky).</p><p>In October last year, Google released the Firestore beta (a pretty stable beta). Prior to that you may be familiar the Firebase product (<a href="https://techcrunch.com/2014/10/21/google-acquires-firebase-to-help-developers-build-better-realtime-apps/">Google acquired Firebase in 2014 — link to Techcrunch announcement</a>) Here’s a quick two minute intro to Firestore:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQcsAb2RR52c%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQcsAb2RR52c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQcsAb2RR52c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ce3f03916de4b992e93d7c1458aa7a6/href">https://medium.com/media/4ce3f03916de4b992e93d7c1458aa7a6/href</a></iframe><h4>How to get Firestore up and running with your React app — super quick</h4><p><strong>Step 1: </strong>Open up your preferred terminal and install <strong><em>firebase </em></strong><em>with npm</em><strong><em><br></em></strong><em>(that’s</em><strong><em> firebase </em></strong><em>not firestore — bare with me here)</em></p><pre>$ npm install firebase</pre><p>You should now have firebase listed in your package.json file — At time of writing, we’re currently on version 5.1.0</p><p><strong>Step 2: Lets create our database — </strong>Head over to the Firebase website: <a href="https://firebase.google.com/">https://firebase.google.com</a> and hit the ‘Get Started’ button — use a preferred gmail account to sign-up. When you’re done with the signup you’ll land on the welcome page with a prompt to create your first project. 👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MO-hJX0W7ka2WrCMFBBwKQ.jpeg" /><figcaption>Firebase welcome page — let’s hit that ‘+ Add project’ card and get building!</figcaption></figure><p>Select the <em>‘Add project’</em> card to create a new project. You’ll be presented with a modal asking you to create a name for your project and identify the region + the obligatory ‘sign your analytics life away’ should you wish to disclose.👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBQfQqsSOc1xnBaYf2if2Q.png" /><figcaption>You can always change your ‘project name’ at a later date through the settings panel</figcaption></figure><p>Next — we want to get the tracking code for our web app, hit the ‘Add Firebase to your web app’ option…👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eldSR6LPF0785FT7gEm3xA.jpeg" /><figcaption>No prizes for guessing which icon to select…</figcaption></figure><p>You’ll be presented with your config code — copy and paste the code within the <em>&lt;script&gt;</em> tags (script tags not needed) 👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1L7ghxihnN3cloc_w2_Yzg.jpeg" /><figcaption>When I was a young lad we used ‘var’….</figcaption></figure><p><strong>Step 3:</strong> Head back over to your React project and let’s create a new <em>Firestore.js</em> component (or whatever you would like to name it). Import firebase into the component and then paste-in the config code. Don’t forget to export the component.</p><p>You should have something similar to this👇👇 <em>don’t worry, the below keys are fictitious, I’m not that trusting! </em>😲</p><pre>import firebase from ‘firebase’;</pre><pre>const config = {<br>   apiKey: &quot;AIzfhrwkKhDBFHbntnKhTahHjkNK6FG875dSB6y&quot;,<br>   authDomain: &quot;typecode-76g33.firebaseapp.com&quot;,<br>   databaseURL: &quot;https://typecode-76g33.firebaseio.com&quot;,<br>   projectId: &quot;typecode-76g33&quot;,<br>   storageBucket: &quot;&quot;,<br>   messagingSenderId: &quot;547432956432&quot;<br>};<br>firebase.initializeApp(config);</pre><pre>export default firebase;</pre><p><strong>Step 4:</strong> Almost there with the Firestore setup, now we need to create our database. Back in Firebase, select the ‘Database’ option from the left-hand navigation and select ‘Create database’ on the Firestore cta. 👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiKOc_cFpAY7NgchrDUEDw.jpeg" /><figcaption>Go create your database…</figcaption></figure><p>Whilst in development, we’ll relax the security preferences to allow <em>‘read’</em> &amp; <em>‘writes’</em> to our database. <em>This will need to be addressed prior to any publishing of your app for obvious security reasons.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnlcHR0q09wWAbaa429JuQ.png" /><figcaption>We’ll use test mode whilst we’re in development 🕵️</figcaption></figure><p><strong>Step 5:</strong> Once enabled, you’ll be presented with your new database. Select the ‘<em>+ Add collection</em>’ option, and create a name for said collection. As highlighted in the tooltip, a collection is a set of documents which contain data. For our example, we’ll use the suggested ‘users’ for creating a database of user details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JP88ZEpQwA7QSKkNKv-XQ.png" /></figure><p>After selecting ‘Next’ we have the option to add a <em>Document id</em> (unique reference) or weleave it blank for Firestore to create a random unique id per document. We’ll leave it blank for now.</p><p>For this example project, we’ll capture two pieces of data from our users, their full name and email address — both are set to string with blank values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ztfn8TR9oKqBMkk03-GITA.png" /></figure><p>Once you’ve specified the data you’re looking to capture, click <em>‘save’. </em>You’ve now created your database, populated with an example document.<br>Time for a sneaky 🙌</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*52iMpE5aCBIDD5dwAycBqA.jpeg" /></figure><p><strong>Step 6: </strong>Ok, with our database created let’s get some data in there. In our project we’ll create a new component called User.js which contains a simple form.</p><pre>import React from &#39;react&#39;;<br>import firestore from &quot;./firestore&quot;;</pre><pre>class User <em>extends</em> React.Component {<br>  render() {<br>    return (<br>        &lt;form&gt;<br>          &lt;input<br>            <em>type</em>=&quot;text&quot;<br>            name=&quot;fullname&quot;<br>            <em>placeholder</em>=&quot;Full name&quot;<br>          /&gt;<br>          &lt;input<br>            <em>type</em>=&quot;email&quot;<br>            name=&quot;email&quot;<br>            <em>placeholder</em>=&quot;Full name&quot;<br>          /&gt;<br>          &lt;button <em>type</em>=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>        &lt;/form&gt;<br>        );<br>      }<br>   }</pre><pre>export default User;</pre><p><strong>Step 7: </strong>Looking good. Now we need to get the data from the form, into the <a href="https://reactjs.org/docs/faq-state.html"><em>state</em></a><em> object </em>(If your not familiar with React’s component state, have a quick run-through the <a href="https://reactjs.org/docs/faq-state.html">React docs here</a>).</p><p>First we’ll create our initial ‘empty’ state inside a constructor function:</p><pre>class User <em>extends</em> React.Component {<br>  <strong>constructor() {<br>    super();<br>    this.state = {<br>     email: “”,<br>     fullname: “”<br>    };<br>  }</strong></pre><pre>  ...</pre><p><strong>Step 8: </strong>Next we’ll add a custom attribute to <strong>both input fields</strong>, which will call a function ‘<em>updateInput’</em> to set our component state, when a user enters data into the form.</p><pre>...</pre><pre><strong>updateInput = e =&gt; {<br>  this.setState({<br>    [e.target.name]: e.target.value<br>  });<br>}</strong></pre><pre>render() {<br>  return (<br>   &lt;form&gt;<br>     &lt;input<br>       t<em>ype</em>=&quot;text&quot;<br>       name=&quot;fullname&quot;<br>       <em>placeholder</em>=&quot;Full name&quot;<br>       <strong>onChange={this.updateInput}</strong><br>      /&gt;<br>    ...</pre><p><strong>Let’s test this:</strong> open up the page in the browser and using React developer tools (Chrome) search for the <em>User</em> component. Now you’ll be able to see the <em>state</em> updated as you type in the form fields — great job!</p><p><strong>Step 9:</strong> Now we’ll add another custom attribute to our input fields. This will assign the data (in <em>state</em>) to our object value which get’s passed into Firestore. (that was succinct…!) like so:</p><pre>...</pre><pre>&lt;form&gt;<br>  &lt;input<br>    <em>type</em>=&quot;text&quot;<br>    name=&quot;fullname&quot;<br>    <em>placeholder</em>=&quot;Full name&quot;<br>    onChange={this.updateInput)<br>    <strong>value={this.state.fullname}<br></strong>  /&gt;<br>  &lt;input<br>    <em>type</em>=&quot;email&quot;<br>    name=&quot;email&quot;<br>    <em>placeholder</em>=&quot;Full name&quot;<br>    onChange={this.updateInput}<br>    <strong>value={this.state.email}</strong><br>  /&gt;<br>&lt;button ...</pre><p>Almost there with the form, we just need to add an attribute to call a function which does the magic when the form is submitted.</p><pre>&lt;form <strong>onSubmit={this.addUser}</strong>&gt;<br>  &lt;input<br>    ...</pre><p><strong>Step 10: </strong>Still with me…? Awesome, we’re nearly there.<br>Let’s create the addUser function which will send data to our Firestore database. We’ll use an arrow function to avoid having to bind <em>this</em> to the function in the constructor — if that doesn’t make sense, <a href="https://reactjs.org/docs/faq-functions.html#why-is-binding-necessary-at-all">read this</a>.</p><pre>addUser = e =&gt; {<br>  e.preventDefault();<br>  this.setState({<br>    fullname: “”,<br>    email: “”<br>  });<br>};</pre><p>Ok, here we’re doing two simple things.<br>1. <em>preventDefault() </em>method stops the page from refreshing (it’s default behaviour)</p><p>2. After the user submits the form, the state is updated to an empty string to remove the user input across both fields.</p><p>Simple enough, now let’s get that data into Firestore:</p><pre>addUser = e =&gt; {<br>  e.preventDefault();<br>  <strong>const db = firebase.firestore();<br>  db.settings({<br>    timestampsInSnapshots: true<br>  });</strong><br>  <strong>const userRef = db.collection(“users”).add({<br>    fullname: this.state.fullname,<br>    email: this.state.email<br>  });</strong>  <br>  this.setState({<br>    fullname: “”,<br>    email: “”<br>  });<br>};</pre><p>Ok, let’s run through what we’re doing here:</p><ol><li>With <em>firebase.firestore()</em> we’re initialising Firestore through firebase and saving to a variable.</li><li><em>timestampsinSnapshots: true </em>without this, we get a warning in the console, which tells us the timestamps stored in Firestore will be read back as timestamp objects, as opposed to system date objects.</li><li><em>db.collection(“users”) </em>is simply pointing to our database; the <em>collection</em> we created called <em>users.</em></li><li>finally the<em> .add()</em> method is submitting our data object with the users full name and email taken from our updated state.</li></ol><p>Hit <em>save, </em>open up the browser and complete the form, hit submit and…</p><p>Magic — you did it! 👇👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c2SeWE9PygpXRMkKd_XwhQ.jpeg" /><figcaption>Great work — you’re now capturing user data in your Firestore db 😄</figcaption></figure><p>As always, this is by no means the <em>only way, right way, best way</em> to get Firestore working with React. This is just one simple route to get things up and running, break down the learning barriers and either move on to another challenge or dive-in further. The <a href="https://firebase.google.com/docs/firestore/quickstart">Firestore documentation</a> is fantastic, so definitely take a peek.</p><p>Go build something brilliant…👊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c78f198d2364" width="1" height="1" alt=""><hr><p><a href="https://medium.com/get-it-working/get-googles-firestore-working-with-react-c78f198d2364">React + Cloud Firestore: Step by step tutorial</a> was originally published in <a href="https://medium.com/get-it-working">Get it working</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get PrismJS working in React]]></title>
            <link>https://medium.com/get-it-working/get-prismjs-working-in-react-a6d989e59290?source=rss-92fbd949935e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6d989e59290</guid>
            <category><![CDATA[prismjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[jason ewins]]></dc:creator>
            <pubDate>Fri, 29 Jun 2018 07:00:49 GMT</pubDate>
            <atom:updated>2019-02-18T14:54:41.799Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yy9I_SW02YiNlcdB7LaGlA.png" /></figure><p>In their own words: <a href="https://prismjs.com/">Prism</a> is a lightweight, extensible syntax highlighter — meaning it can be used to highlight code blocks or code samples in a website.</p><p>A bit like the way we can display markup in Medium, as below:</p><pre>onSubmit(e) {<br>  e.preventDefault();<br>  const job = {<br>     title: &#39;Developer&#39;,<br>     company: &#39;Facebook&#39; <br>  };<br>}</pre><p>Only with <a href="https://prismjs.com/">Prism</a>, we get a lot more control over styling. Which means we can make coding tutorials look as awesome as the likes of <a href="https://css-tricks.com/">CSS tricks</a> and documentation as clear as that of <a href="https://reactjs.org/docs/getting-started.html">React.js</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-Dczr_d7mr_t-yy-zwicg.png" /><figcaption>CSS Tricks — looking 🔥</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhaTiceB0_XoZE4o1xplsg.png" /><figcaption>React use Prism.js to highlight code in their documentation</figcaption></figure><h4><strong>How to get Prism working with create-react-app — super quick.</strong></h4><p><strong>Step 1:</strong> Open up the terminal and install prismjs with npm</p><pre>$ npm install prismjs</pre><p><strong>Step 2: </strong>Import prismjs into your component</p><pre>import React from &quot;react&quot;;<br><strong>import Prism from &quot;prismjs&quot;;</strong></pre><p><strong>Step 3:</strong> Select your preferred theme type from the <a href="https://prismjs.com/download.html#themes=prism-okaidia&amp;languages=markup+css+clike+javascript">prism website</a> — ( I like Okadia) and hit that rather large DOWNLOAD CSS button at the foot of the page. (Quick note: to preview theme types, you’ll have to scroll between the theme section and foot of the page).</p><p>Then simply add the prism.css file to your corresponding ‘src’ directory (I use a separate stylesheet per component) and remember to import the file to the component.</p><pre>import React from &quot;react&quot;;<br>import Prism from &quot;prismjs;<br><strong>import &quot;../css/prism.css&quot;;</strong></pre><p><strong>Step 4:</strong> In your desired component, create your code block using the semantic <em>&lt;pre&gt;</em> and <em>&lt;code&gt;</em> HTML5 tags. Prism works by changing the code within these tags to make it appear as though it’s been written in a code editor.</p><p>We also need to wrap the code with ES6 template strings - back-ticks wrapped in curly braces, like so <em>{`code goes here`}</em></p><p>So, using our example code block from before:</p><pre>&lt;pre&gt;<br>  &lt;code&gt;<br>  {`<br>    onSubmit(e) {<br>      e.preventDefault();<br>      const job = {<br>        title: &#39;Developer&#39;,<br>        company: &#39;Facebook&#39; <br>        };<br>      }<br>  &#39;}<br>  &lt;/code&gt;<br>&lt;/pre&gt;</pre><p>Want to learn more about the <em>&lt;pre&gt;</em> &amp; <em>&lt;code&gt;</em> tags — <a href="https://stackoverflow.com/questions/16065677/what-is-difference-between-pre-and-code-html-tag">this stack overflow thread has you covered</a></p><p><strong>Step 5: </strong>add the relative className for the language</p><h4>For CSS:</h4><pre>&lt;pre&gt;<br>  &lt;code <strong>className=”language-css”</strong>&gt;<br>    .btn--green {<br>     background-color: #bada55;<br>    }</pre><h4>For JavaScript:</h4><pre>&lt;pre&gt;<br>  &lt;code <strong>className=&quot;language-javascript&quot;</strong>&gt;<br>    onSubmit(e) {<br>      ....</pre><p><strong>Step 6: </strong>Open the browser, preview the site, and….oh!<strong> Why’s it not working…?</strong></p><p>If you hit <em>refresh</em>…you’ll see Prism spring to life and your syntax looks sweet — so why will it not load when the page is initially rendered?</p><p>Because we’re using React and therefore JavaScript to render the page we need to <em>re-run</em> Prism when the component mounts, as Prism has not yet been called to run on the component — kinda fussy huh! (this is one of those issues that can leave you scratching your head for a couple of hours).</p><p>When the page loads, Prism drops an object on the page with a bunch of methods, and we can use <a href="https://prismjs.com/extending.html">one of these methods</a> to initialise the library.</p><p><em>Prism.highlightAll()</em></p><p>We then use one of <a href="https://reactjs.org/docs/glossary.html#lifecycle-methods">React’s built-in lifecycle methods</a> to run prism when the component mounts:</p><p><em>componentDidMount() {}</em></p><p>Place it directly after the component class definition, as below:</p><pre>class Codeblock <em>extends</em> React.Component {<br>  <strong>componentDidMount() {<br>    Prism.highlightAll();<br>  }</strong></pre><pre>render() {<br>  return (</pre><p>Preview your site once more and voila…there you have it…🔥</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SSOFMWRbu3tkxgtWdEyi6g.png" /></figure><p>This is by no means the <em>only way, right way, best way</em> to get Prism working with React. You don’t need to use npm, you could simply use the raw JavaScript file, or you could use the <a href="https://cdnjs.com/libraries/prism">CDN version</a>, and improve performance. This is just one simple route to get things up and running, break down the learning barriers and either move on to the next challenge, or get stuck in with customising Prism further.</p><p>Let me know if it helps…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6d989e59290" width="1" height="1" alt=""><hr><p><a href="https://medium.com/get-it-working/get-prismjs-working-in-react-a6d989e59290">Get PrismJS working in React</a> was originally published in <a href="https://medium.com/get-it-working">Get it working</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>