A tiny ~700b centralized state container with component bindings for Preact. #reactjs #preact

  • { , , } store ({ count }) If actions is a function, it gets passed the store: ({ ( ) { { count . } }
  • , The above example as an Arrow Function: ({ count }) ({ count count }), ( ) { res ( ) { stuff .
  • , ) } }) ( , actions)( ({ count, increment }) ( div p Count {count} p button onClick {increment} Increment button div ) ) () ( Provider store {store} App Provider ) – – Creates a new store, which is a tiny evented state container.
  • Register a listener function to be called whenever state is changed.
  • If don’t, just open a new clear and descriptive issue.

unistore – 🌶 700b state container with component actions for Preact
Continue reading “A tiny ~700b centralized state container with component bindings for Preact.
#reactjs #preact”

Structuring React and Redux Applications – Frontend Weekly – Medium

Structuring #ReactJS and #Redux applications:

  • It’s annoying and difficult to explain to new team members.Now I group files by view or page: dashboard, users, etc.Here are main folders I have in my application:app: Redux store configuration and root reducer, React Router routes, application root components with connections to Redux, Redux DevTools, React Router and React Intl.components: shared components.models: Immutable.js records.util: any shared non-React JavaScript code.features.Feature folders look like this:features/ feature-name/ components/ FeatureNameView.jsx FeatureNameLayout.jsx *.
  • I also put Reselect selectors into the duck file as selector named export.The components folder contains all React components that are unique to this view.FeatureNameView is connected to Redux and contains all action calls.
  • All page layout goes to FeatureNameLayout component.Ducks and selectorsEach feature has its own duck file duck.js structured as follows:import { combineReducers } from ‘redux’;import { createStructuredSelector } from ‘reselect’;const DO_SOMETHING_COOL = Actionsexport function doSomethingCool(what) { return { type: DO_SOMETHING_COOL, // … };}// Reducersfunction cookiesReducer(state, action) { switch (action.type) { case DO_SOMETHING_COOL: return {/*_*/}; default: return {/*_*/}; }}export default combineReducers({ cookies: cookiesReducer, // …});// Selectorsconst isFetching = state = state.isFetching;const cookies = state = state.data.cookies;export const selector = createStructuredSelector({ isFetching, cookies,});Then import it at the root reducer, app/reducers.
  • So I connect selectors and actions to feature’s root component, FeatureNameView.jsx:import React, { Component, PropTypes } from ‘react’;import { bindActionCreators } from ‘redux’;import { connect } from ‘react-redux’;import * as duck from ‘.
  • /duck’;import FeatureNameLayout from = dispatch = ({ actions: bindActionCreators(duck, dispatch),}))export default class FeatureNameView extends Component { /* Here you have: – – this.props.isFetching – this.props.cookies */ handleSomethingCool(what) { } render() { const { isFetching } = this.props; return ( div {isFetching ?

There’s no idiomatic way to structure Redux applications yet. And I believe there’s no The Only True Project Structure but I’ll describe what works for me. I started from grouping by type. It works…
Continue reading “Structuring React and Redux Applications – Frontend Weekly – Medium”

ZEIT – Next.js 2.0

Next.js 2.0

  • When we launched Next.js, there was no way to do dynamic routing or load your custom server code.
  • This has tremendous benefits, at the tiny cost of two extra parameters in the initial `install` to set up your project:

    Our mission is to make Next.js as familiar as possible to developers on the Web Platform.

  • Each top-level component (page) in Next.js defines the entirety of the document .
  • We’ve very thankful to our community for having submitted so many examples of backends (Express, HAPI, Koa…), styling systems (cxs, glamor, styled-components…), testing systems (jest), type systems (TypeScript and Flow), data fetching (Apollo) and many others.
  • This will allow for server-rendered pages that expose different JS components according to the data they used, for example.

Next.js 2.0 comes packed with performance improvements and extensibility features
Continue reading “ZEIT – Next.js 2.0”

Scaling your Redux App with ducks – freeCodeCamp

Scaling your Redux App with ducks:  by @alexnmoldovan #ReactJS #Redux #JavaScript

  • A single flow through your app will probably require files from all folders.
  • Selector functions take a slice of the application state and return some data based on that.
  • The file specifies what gets exported from the duck folder.
  • You end up with a folder common or shared, because you want to reuse code across many features in your app.
  • The solution was to split each feature into a duck folder.

How does your front-end application scale? How do you make sure that the code you’re writing is maintainable 6 months from now? Redux took the world of front-end development by storm in 2015 and…
Continue reading “Scaling your Redux App with ducks – freeCodeCamp”

Rapid cross-platform mobile development with React Native

  • We can avoid the need for lots of upfront planning and naturally fall into certain conventions and patterns of data fetching and state management.
  • import React, { Component } from ‘react’
  • React Native exposes the Platform module, which detects the platform on which the app is currently running.
  • Sometimes we may need to diverge our application flow by platform in order to perform the appropriate action, but often it’s as simple as swapping some values around based on the current platform.
  • Platform-specific extensions allow us to write a separate file for each platform, e.g. button.ios.js and button.android.js .

How React Native helped us ship a cross-platform mobile app in 8 weeks.
Continue reading “Rapid cross-platform mobile development with React Native”

Using ReactJS in WordPress Plugins – Nabeel

Using ReactJS in WordPress Plugins

  • Using ReactJS in WordPress Plugins
  • I then used jQuery to turn those icons on and off as needed, and talk to the server via an endpoint in the plugin .
  • As I got more comfortable with React, I started thinking about the possibility of using it in the Sift Science plugin.
  • When I first started developing the Sift Science for WooCommerce plugin last year, I needed interactive controls on the Orders page that displayed fraud scores and allowed the admin to flag fraudulent users.
  • I started out by implementing a new feature in React to see if it was feasible.

When I first started developing the Sift Science for WooCommerce plugin last year, I needed interactive controls on the Orders page that displayed fraud scores and allowed the admin to flag fraudulent users. I didn’t want to reload the page every time the user took an action, so the obvious solution was to implement some client-side scripting and background Ajax calls to the server.
Continue reading “Using ReactJS in WordPress Plugins – Nabeel”