Server Rendering with React and React Router

Server Rendering with React and React Router, by @tylermcginnis  #reactjs #react

  • Now that we get the big picture, let’s work on creating the foundation for what will become a server rendered React Router app.
  • Here’s what the React docs have to say about this – – When you’re just rendering a component with no data, it’s not difficult to have the server rendered and client rendered content be identical – as we saw when we just rendered .
  • You need to make sure that the component is rendered with the same data (or props) on both the client and server.
  • The idea is when a GET request is made to our server, instead of calling immediately, we fetch the popular repositories first and then call it after giving our React app the data.
  • The client because it obviously needs to know which components to render as the user navigates around our app and the server because it needs to know which data to fetch when the user requests a specific path.

Continue reading “Server Rendering with React and React Router”

Give React Native a(nother) try + ReactNative Navigation

  • React Native is no different from other – – tools in this regard, so I want to present a few reasons why you might want to give – – React Native a(nother) try now, just over two and a half years since its initial release.
  • # Native Navigation with React Navigation – – – – You start using React Native.
  • You can either use a library that wraps the native navigation APIs for the platform or a re-implementation of those APIs using the same React Native primitives (View, Text, Animated, etc) that you use throughout your app.
  • React Navigation ( is a “JavaScript-based” navigation solution and React Native Navigation is a “native” navigation library.
  • I lead the React Navigation along with the creator of the project, Eric Vicenti.

Brent Vatne (, ReactNative) and Eric Vicenti (ReactNative @Facebook) are in town delivering training…# Reasons to give React Native a(nother) tryWhen a highly hyped new tool is released, many
Continue reading “Give React Native a(nother) try + ReactNative Navigation”

React: Re-render a Component On Route (or props) Change

React: Re-render a Component On Route (or props) Change #React #reactjs

  • /TableContainer”;const App = () = { – return ( – React.Fragment – Switch – Route exact path=”/subscribers” component={TableContainer} / – Route exact path=”/leads” component={TableContainer} / – /Switch – /React.Fragment – ); – };export default App;ReactDOM.render( – HashRouter – App / – /HashRouter, – )As you can see TableContainer is the…
  • /Table”; – import axios from “axios”;class TableContainer extends Component { – constructor() { – super();this.state = { – data: [], – loaded: false, – placeholder: “Loading…” – }; – }componentDidMount() { – }getData(pathname) { – axios – .
  • Seems like a good candidate for calling an API In fact the signature for the method means it is possible to read the new pathname workflow becomes clear: – call the API inside componentDidMount when the component mounts the first timecall the API again inside componentWillReceiveProps when the component is…
  • /Table”; – import axios from “axios”;class TableContainer extends Component { – constructor() { – super();this.state = { – data: [], – loaded: false, – placeholder: “Loading…” – }; – }componentDidMount() { – { – }getData(pathname) { – axios – .
  • Table data={data} / : p{placeholder}/p; – } – }export default TableContainer;Now the TableContainer component: – calls the corresponding endpoint on first mountcalls api/subscribers/ if Route changes to /subscriberscalls api/leads/ if Route changes to /leadsNeat!

It makes sense to have a single React component for calling the API endpoints depending on the location pathname. With the application in place I can see the expected data if I click either on /leads…
Continue reading “React: Re-render a Component On Route (or props) Change”

React: Re-render a Component On Route Change

  • In other words: reloading/refreshing the same React component when visiting a link.
  • It makes sense to have a single React component for calling the API endpoints depending on the location pathname.
  • As you can see TableContainer is the only React component for fetching data.
  • More about presentational and container components: writing React components – – It should call the appropriate endpoint whenever I click /subscribers or /leads.
  • A single React component can fetch the data from different endpoints depending on the location pathname.

A common scenario with React Router: re-render a component on route change
Continue reading “React: Re-render a Component On Route Change”

One `npm publish` away from releasing version 1.5.0 of `react-native-maps-directions` :) 🔗

One `npm publish` away from releasing version 1.5.0 of `react-native-maps-directions` :)


  • Directions component for – Draw a route between two coordinates, powered by the Google Maps Directions API – – Import and render it as a child of a component.
  • The mandatory props are: – – Once the directions in between and has been fetched, a between the two will be drawn.
  • Since the result rendered on screen is a component, all props – except for – are also accepted.
  • The values for the and props can take several forms.
  • They can either be: – – All examples below have the same location, represented in the formats mentioned above: – – Note: The and props don’t need to use the same representation, you may mix them.

react-native-maps-directions – Directions Component for `react-native-maps`
Continue reading “One `npm publish` away from releasing version 1.5.0 of `react-native-maps-directions` 🙂


nohoist in Workspaces

  • First, let’s take a quick tour on how hoist work in standalone projects: – – To reduce redundancy, most package managers employ some kind of hoisting scheme to extract and flatten all dependent modules, as much as possible, into a centralized location.
  • In such project, modules could be scattered in multiple locations: – – yarn workspaces can share modules across child projects/packages by hoisting them up to their parent project’s node_modules: .
  • Consequently, workspaces developers often witness “module not found” related errors when building from the child project: – – For this monorepo project to reliably find any module from anywhere, it needs to traverse each nodemodules tree: *“monorepo/nodemodules”* and .
  • There are indeed many ways library owners can address these issues, such as multi-root, custom module map, clever traversing scheme, among others… However, – – It is frustrating when a solution worked for a standalone project only fell short in the monorepo environment.
  • Module path is a virtual path of the dependency tree, not an actual file path, so no need to specify “node_modules” or “packages” in the nohoist pattern.

As wonderful as yarn workspaces are, the rest of the community hasn’t yet fully caught up with the monorepo hoisting scheme. The introducing of the nohoist i…
Continue reading “nohoist in Workspaces”

Using JSX and React #React #reactjs #javascript #Framework #programming

Using JSX and React  #React #reactjs #javascript #Framework #programming

  • Form creation is easy with JSX and sub-components, for example: – – To make this work, you must create the sub-components as attributes of the main component: – – To use some JavaScript to create a result for use in an attribute value, React just needs you to wrap it…
  • _disconnectFrom(userId); self.emit(events.DISCONNECT, userId); console.log(‘User disconnected’, userId); }); }); console.log(‘Connecting with username’, username); this.peer = new Peer(username, { host: location.hostname, port: 9000, path: ‘/chat’ }); this.peer.on(‘open’, function (userId) { self.setUsername(userId); }); this.peer.on(‘connection’, function (conn) { self.
  • First we use to establish signalling of a new user connected via the as so: – – js ChatServer.prototype.connect = function (username) { var self = this; this.setUsername(username); this.socket = io(); this.socket.on(‘connect’, function () { self.socket.on(events.CONNECT, function (userId) { if (userId === self.getUsername()) { return; } self.
  • _connectTo(userId); self.emit(events.CONNECT, userId); console.log(‘User connected’, userId); }); – – Then, to connect to the PeerServer, we use the following: – – We then listen for events via the method: – – We also have our JSX inside components in the directory.
  • Now it’s as simple as pushing your code to heroku: – – Once the push is finished, you will be able to start your web service with the following: – – Now just visit the URL provided, or as a shortcut use the command as so: – – You’ve learned…

What You’ll Be CreatingJSX is similar to a mix of XML and HTML. You use JSX within React code to easily create components for your apps. JSX transforms into JavaScript when React compiles the…
Continue reading “Using JSX and React #React #reactjs #javascript #Framework #programming”

ReactJS App With Laravel RESTful API Endpoint Part 1

  • [] : [ new new new mangle: false, sourcemap: false }), ],};Webpack is a module bundler that packs all our source code within the public/js/ folder into one single file “bundle.js” which would be referenced from our laravel blade view.Step 2From the routes/web.
  • — Bootstrap Core CSS — link rel=”stylesheet”/headbodydiv id=”app”/divscript div container div id=”app”/div is the actual wrapper for our react components.Also create a JavaScript file under public/js/ folder called app.js,import React from “react”;import ReactDOM from “react-dom”;import {Router, Route, IndexRoute, browserHistory} from “react-router”;import Layout from “.
  • /components/Articles”;const app = Router history={browserHistory} Route path=”/” component={Layout} IndexRoute component={Home}/IndexRoute Route path=”users” component={Users}/Route Route path=”articles” component={Articles}/Route /Route /Router,app);The first three lines are import statements for importing the react packages we would be using in this file.Then we import the Layout component from React from “react”;import { Link } from “react-router”;import…
  • “collapse” : “”;return(div class=”navbar navbar-default navbar-fixed-top” div class=”container” div class=”navbar-header” a href=”#/” class=”navbar-brand”My React App/a button class=”navbar-toggle” type=”button” span class=”sr-only”Toggle Navigation/span span class=”icon-bar”/span span class=”icon-bar”/span span class=”icon-bar”/span /button /div div class={“navbar-collapse ” + navClass} id=”navbar-main” ul class=”nav navbar-nav” li class={homeClass} IndexLink to=”/” /li li class={usersClass} Link to=”users” /li li class={articlesClass}…
  • Alternatively you can run$ webpack –watchThis would always watch for changes within the public/js/ folder and then re-bundle the project instead of always running the npm webpack command every single time we make changes to the project.Then we run$ php artisan serveto start the Laravel development server which would be…

From my previous two articles, I introduced Laravel RESTful API Development, which was a step by step approach of creating a RESTful API endpoint for other apps to connect to it. In this series I…
Continue reading “ReactJS App With Laravel RESTful API Endpoint Part 1”

Making ReactJS Realtime With Websockets

Making #ReactJS Realtime With #Websockets

  • Installation – Now, install create-react-app and also scaffold a new React app with the following commands: – npm install -g create-react-app – – create-react-app react-pusher – – Once all the necessary files are installed, change directory into react-“pusher and start the application with: – npm start – – By now,…
  • There are number of dependencies required for the application server, so let’s install them immediately: – npm install –save axios body-parser cors express pusher pusher-js – – To configure the entry point of the application, create a file called server.js and paste the code below into it: – const Pusher…
  • /ChatBox.css’; – export default ({ text, username, handleTextChange }) = ( – div – div className=”row” – div className=”col-xs-12″ – div className=”chat” – div className=”col-xs-5 col-xs-offset-3″ – input – type=”text” – value={text} – placeholder=”chat here…” – className=”form-control” – onChange={handleTextChange} – onKeyDown={handleTextChange} – / – /div – div className=”clearfix”/div – /div…
  • /avatar.png”; – export default ({ chats }) = ( – ul – { = { – return ( – div – div className=”row show-grid” – div className=”col-xs-12″ – – div className=”chatMessage” – div key={} className=”box” – p – strong{chat.username}/strong – /p – p{chat.message}/p – /div – div className=”imageHolder” – img…
  • The state variables in the app are created and defined in the constructor like this: – … – class App extends Component { – constructor(props) { – super(props); – this.state = { – text: ”, – username: ”, – chats: [] – }; – } – componentDidMount() { – ……

This quick tutorial will lead you through building a basic, realtime group chat app, similar to our demo here…
Continue reading “Making ReactJS Realtime With Websockets”

Show a Text over an Image at Mouse Location using jQuery

  • The code example here in this post explains how to show a text over an Image at mouse location using jQuery.
  • You can easily such as an image at the precise mouse location using jQuery.
  • You can either move the mouse over an image and get the location (coordinates) or click the mouse at any point on the image and get its coordinates.
  • I’ll show you can show a text or some message at the precise location of the mouse click on an image.
  • This is how you can get the coordinates or location of the mouse and place a text at the location.

The code example here in this post explains how to show a text over an Image at mouse location using jQuery.
Continue reading “Show a Text over an Image at Mouse Location using jQuery”