Skip to content

Instantly share code, notes, and snippets.

View ryandrewjohnson's full-sized avatar

Ryan Johnson ryandrewjohnson

View GitHub Profile
import React from 'react';
import { connect } from 'react-redux';
import Alert from 'components/Alert';
import Modal from 'components/Modal';
const mapStateToProps = state => ({
isOpen: state.modals.isAlertOpen,
children: React.createElement(Alert)
});
import React from 'react';
const ToggleRadio = props => {
const { heading, group, radio1, radio2 } = props;
return (
<div>
<fieldset>
<legend>{ heading }</legend>
<input id={ radio1.id } name={ group } value={ radio1.value } type="radio" />
<label for={ radio1.id }>{ radio1.label }</label>
@ryandrewjohnson
ryandrewjohnson / app.jsx
Last active July 1, 2018 00:47
react-localize-redux - app.js
import React from "react";
import { render } from "react-dom";
import { BrowserRouter as Router, Route } from "react-router-dom";
import { LocalizeProvider } from "react-localize-redux";
import Main from "./Main";
const App = props => (
<LocalizeProvider>
<Router>
<Route path="/" component={Main} />
@ryandrewjohnson
ryandrewjohnson / initialize.jsx
Last active July 1, 2018 00:50
react-localize-redux - setLanguages.js
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { withLocalize } from "react-localize-redux";
import globalTranslations from "./translations/global.json";
class Main extends React.Component {
constructor(props) {
super(props);
this.props.initialize({
@ryandrewjohnson
ryandrewjohnson / addTranslationForLanguage.jsx
Last active July 1, 2018 00:57
react-localize-redux - addTranslationForLanguage.jsx
import frenchMovieTranslations from "./translations/fr.movies.json";
this.props.addTranslationForLanguage(frenchMovieTranslations, "fr");
@ryandrewjohnson
ryandrewjohnson / global.json
Last active July 12, 2017 00:10
react-localize-redux - global.js
{
"title": ["Movie Reviews"],
"search": ["<a href='http://www.imdb.com/'>Search IMDb</a>"],
"copyright": ["copyright ${ year }"]
}
@ryandrewjohnson
ryandrewjohnson / movie.json
Created July 12, 2017 00:14
react-localize-redux - movie.json
{
"movie": {
"title": ["Jurassic Park"],
"desc": ["Lots of dinos!"],
"stars": ["${ stars } out of 5"]
}
}
@ryandrewjohnson
ryandrewjohnson / addTranslation.jsx
Last active July 1, 2018 00:54
react-localize-redux - addTranslations.js
import React from "react";
import { withLocalize } from "react-localize-redux";
import movieTranslations from "./translations/movies.json";
class Movies extends React.Component {
constructor(props) {
super(props);
this.props.addTranslation(movieTranslations);
}
@ryandrewjohnson
ryandrewjohnson / translate-with-defaults.jsx
Last active July 1, 2018 01:00
react-localize-redux - Translate with default translations:
import React from "react";
import { Translate } from "react-localize-redux";
const Movies = props => (
<h1>
<Translate id="movie.title">Jurassic Park</Translate>
</h1>
);
@ryandrewjohnson
ryandrewjohnson / translate-selfclosing.jsx
Last active July 1, 2018 01:02
react-localize-redux - Translate with self-closing tag
const Movies = props => (
<h1>
<Translate id="movie.title" />
</h1>
);