Skip to content

Instantly share code, notes, and snippets.

View lomse's full-sized avatar
😄
Working on a React Redux project

Sélom lomse

😄
Working on a React Redux project
View GitHub Profile
@lomse
lomse / TodoList.jsx
Created October 20, 2018 15:17
TodoList component
import React from "react"
import styled from "styled-components"
import PropTypes from "prop-types"
import TodoItem from "./TodoItem"
const StyledUl = styled.ul`
padding: 0;
`
const TodoList = props => {
@lomse
lomse / TodoItem.jsx
Last active October 20, 2018 15:16
TodoItem component
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
const StyledList = styled.li`
list-style: none;
overflow: hidden;
width: 100%;
margin-bottom: 10px;
`
@lomse
lomse / TodoItem.test.js
Last active October 20, 2018 15:10
Snapshot test for TodoItem component with Enzyme
import React from "react"
import Enzyme, { shallow } from "enzyme"
import Adapter from "enzyme-adapter-react-16"
import TodoItem from "./TodoItem"
describe("TodoItem Component", () => {
beforeAll(() => {
Enzyme.configure({ adapter: new Adapter() })
})
@lomse
lomse / App.jsx
Created October 20, 2018 14:50
App.jsx updated to add new todos
import React, { Component } from 'react'
import styled from 'styled-components'
import { generateId, addTodo } from '../lib/helper'
import TodoList from './TodoList'
import TodoForm from './TodoForm'
const Container = styled.div`
width: 250px;
margin: 10px auto;
font-family: Arial, Helvetica, sans-serif;
handleSubmit = evt => {
evt.preventDefault()
const { currentTodo, todos } = this.state
const newTodo = { id: generateId(), name: currentTodo, isComplete: false }
const updatedTodos = addTodo(todos, newTodo)
this.setState({ todos: updatedTodos, currentTodo: '' })
@lomse
lomse / TodoForm.jsx
Created October 20, 2018 10:18
TodoForm.jsx with events
import React from 'react'
import styled from 'styled-components'
import PropTypes from 'prop-types'
const FormInput = styled.input`
width: 235px;
outline: none;
font-size: 13px;
padding-top: 7px;
padding-bottom: 7px;
@lomse
lomse / TodoForm.test.js
Created October 11, 2018 00:46
Snapshot Tests for the TodoForm component
import React from 'react'
import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import TodoForm from './TodoForm'
describe('TodoForm Component', () => {
beforeAll(() => {
Enzyme.configure({ adapter: new Adapter() })
})
@lomse
lomse / webpack.config.js
Created October 11, 2018 00:43
Entry point to point to index.jsx file instead of the App.jsx file
const path = require('path')
const config = {
context: __dirname,
entry: './src/index.jsx',
devtool: 'cheap-eval-source-map',
output: {
path: path.join(__dirname, 'public/js'),
filename: 'bundle.js'
},
@lomse
lomse / App.jsx
Created October 11, 2018 00:41
App.jsx
import React from 'react'
import styled from 'styled-components'
import TodoList from './TodoList'
import TodoForm from './TodoForm'
const Container = styled.div`
width: 250px;
margin: 10px auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px
@lomse
lomse / index.jsx
Created October 11, 2018 00:40
Move the render logic to from App.jsx to index.jsx file
import React from 'react'
import { render } from 'react-dom'
import App from './components/App'
render(<App />, document.getElementById('app'))