Skip to content

Instantly share code, notes, and snippets.

View codervince's full-sized avatar

Vince codervince

  • Melbourne, Australia
View GitHub Profile
@codervince
codervince / React.Component.js
Last active July 6, 2017 06:52
React.Component.js
// Add all useful state specific functions here
export class App extends ReactComponent {
constructor(props){
super(props)
this.state = {products: [{....}]}
//
_handleRemoveLast() {
this.setState({
@codervince
codervince / React.ExternalComponentWrapper.js
Created July 6, 2017 07:08
Creating an external wrapper to am npm component not written for react
//implements API, looks like a regular R component
//just displays data as JSON
//uses JSON-Formatter.js https://github.com/mohsen1/json-formatter-js
//bundler must have acess to node_modules/dist/bundle.js
//bind in HTML via <script)
//JSONViewer.js
export class JSONViewer extends React.Component {
@codervince
codervince / react.redux.js
Created July 8, 2017 03:13
Redux and integrating in react - best to outsource the conversion
//actions.js
export const ADD_PRODUCT = 'ADD_PRODUCT';
export const CLEAR_FORM = 'CLEAR_FORM';
....
//NB Reducers MUST be pure functions
/* action creators */
export function addProduct(product){
//MainLayout
const linkStyle={activeStyle: {color:'red'}}
export const MainLayout = props => {
<div>
...
//default Default loser
<Link to="/greeting/loser/default" {...LinkStyle}> Welcome,. Loser</Link>
//magic taken care of by REACT ROUTER see nested Routes in Router index.js