Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React & Redux @ Grillcon 2017

React & Redux @ Grillcon 2017

React & Redux talk from Grillcon 2017

Avatar for Mattias Lyckne

Mattias Lyckne

September 15, 2017
Tweet

Other Decks in Programming

Transcript

  1. React React Native React Native Windows React Native for web

    React VR React Hardware React PDF Learn Once, Write Anywhere React DocX React Sketchapp React Blessed Spectacle and much more
  2. import React from 'react'; import Text from './text'; import ReactDOM

    from 'react-dom'; ReactDOM.render( <Text text="Hello Grillcon!" />, document.getElementById('root') );
  3. import React from 'react'; class TextInput extends React.Component { constructor(props)

    { super(props); this.state = { text: props.text }; } handleChange(evt) { this.setState({text: evt.target.value}); } render() { return ( <div> <input onChange={this.handleChange} value={this.state.text} /> <p>{this.state.text}</p> </div> ); } }
  4. Payload of information you send to the store. Actions {

    type: 'SAVE_SEARCH', query: 'Playstation' }
  5. Function that creates an action Action creators function saveSearch(query) {

    return { type: 'SAVE_SEARCH', query: query, }; }
  6. Take an action and specify how the application states changes.

    Reducers function reducer(state, action) { if (action.type === 'SAVE_SEARCH') { return { ...state, savedSearches: state.savedSearches.concat(action.query) }; } return state; }
  7. 1. store.dispatch(action); 2. Redux store calls the reducer 3. Redux

    store saves the state returned by the root reducer Redux flow
  8. Easy setup Instant feedback Snapshots Jest React Testing Utility jQuery-like

    API to manipulate and traverse React components Enzyme
  9. import { shallow } from enzyme; import SaveSearch from '../save-search';

    describe('SaveSearch', () => { it('renders without crashing', () => { shallow(<SaveSearch />); }); it('calls function on onClick', () => { const func = jest.fn(); const wrapper = shallow(<SaveSearch onClick={func} />); wrapper.find('button').simulate('click'); expect(func).toHaveBeenCalled(); }); });
  10. yarn create react-app yarn add redux react-redux yarn add --dev

    redux-devtools yarn add --dev enzyme react-test-renderer Start coding