import React from "react"
function TodoItem() {
return (
Placeholder text here
)
}
export default TodoItem
App.js
import React from "react"
import TodoItem from "./TodoItem"
function App() {
return (
)
}
export default App
style.css
body {
background-color: whitesmoke;
}
.todo-list {
background-color: white;
margin: auto;
width: 50%;
display: flex;
flex-direction: column;
align-items: center;
border: 1px solid #efefef;
box-shadow:
/* The top layer shadow */
0 1px 1px rgba(0,0,0,0.15),
/* The second layer */
0 10px 0 -5px #eee,
/* The second layer shadow */
0 10px 1px -4px rgba(0,0,0,0.15),
/* The third layer */
0 20px 0 -10px #eee,
/* The third layer shadow */
0 20px 1px -9px rgba(0,0,0,0.15);
padding: 30px;
}
.todo-item {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 30px 20px 0;
width: 70%;
border-bottom: 1px solid #cecece;
font-family: Roboto, sans-serif;
font-weight: 100;
font-size: 15px;
color: #333333;
}
input[type=checkbox] {
margin-right: 10px;
font-size: 30px;
}
input[type=checkbox]:focus {
outline: 0;
}
10.lesson 21
(1)ContactCard.js
import React from "react"
function ContactCard(props) {
return (
{props.name}
Phone: {props.phone}
Email: {props.email}
)
}
export default ContactCard
(1)App.js
import React from "react"
import ContactCard from "./ContactCard"
function App() {
return (
)
}
export default App
(2)ContactCard.js
import React from "react"
function ContactCard(props) {
console.log(props)
return (
{props.contact.name}
Phone: {props.contact.phone}
Email: {props.contact.email}
)
}
export default ContactCard
(2)App.js
import React from "react"
import ContactCard from "./ContactCard"
function App() {
return (
)
}
export default App
11.lesson 23
App.js
import React from "react"
import Joke from "./Joke"
import jokesData from "./jokesData"
function App() {
const jokeComponents = jokesData.map(joke => )
return (
{jokeComponents}
)
}
export default App
jokesData.js
const jokesData = [
{
id: 1,
punchLine: "It’s hard to explain puns to kleptomaniacs because they always take things literally."
},
{
id: 2,
question: "What's the best thing about Switzerland?",
punchLine: "I don't know, but the flag is a big plus!"
},
{
id: 3,
question: "Did you hear about the mathematician who's afraid of negative numbers?",
punchLine: "He'll stop at nothing to avoid them!"
},
{
id: 4,
question: "Hear about the new restaurant called Karma?",
punchLine: "There’s no menu: You get what you deserve."
},
{
id: 5,
question: "Did you hear about the actor who fell through the floorboards?",
punchLine: "He was just going through a stage."
},
{
id: 6,
question: "Did you hear about the claustrophobic astronaut?",
punchLine: "He just needed a little space."
}
]
export default jokesData
12.lesson 24
Product.js
import React from "react"
function Product(props) {
return (
/*
Challenge:
1. Convert all 3 components to be class-based
2. Fix the small bug
*/
import React, {Component} from "react"
import ReactDOM from "react-dom"
// #1
class App extends React.Component {
render() {
return (
import React,{Component} from "react"
// Challenge:
// Given an incomplete class-based component without a constructor,
// add a constructor and initialize state to fix the broken component.
class App extends Component{
constructor(){
super()
this.state={
name:"AAA",
age:"18"
}
}
render(){
return (
{this.state.name}
{this.state.age} years old
)
}
}
export default App
18.lesson 30
React State Practice 2
import React,{Component} from "react"
// Given a stateless functional component, add state to it
// state should have a property called `isLoggedIn` which is a boolean
// (true if logged in, false if not)
// Then, give your best shot at rendering the word "in" if the user is logged in
// or "out" if the user is logged out.
class App extends Component{
constructor(){
super()
this.state={
isLoggedIn:false
}
}
render(){
let display
if(this.state.isLoggedIn){
display = "in"
}else{
display="out"
}
return (
You are currently logged {display}
)
}
}
export default App
19.lesson 31
React Todo App: Phase 4
App.js
/*
In the previous iteration of this todo list app, we pulled in todos data from a JSON file and mapped over it to display the todo items.
Eventually we'll want to be able to modify the data, which will only happen if we've "loaded" the data in to the component's state
Challenge: Change the component into a stateful class component and load the imported `todosData` into state.
*/
import React from "react"
import TodoItem from "./TodoItem"
import todosData from "./todosData"
class App extends React.Component {
constructor() {
super()
this.state = {
todos: todosData
}
}
render() {
const todoItems = this.state.todos.map(item => )
return (
{todoItems}
)
}
}
export default App
20.lesson 32
Handling Events in React
App.js
import React from "react"
function handleClick() {
console.log("I was clicked")
}
// https://reactjs.org/docs/events.html#supported-events
function App() {
return (
/**
* Challenge: Get rid of our warning about not having an onChange on our input. For now, the function that runs onChange can simply console.log something.
*/
import React from "react"
function TodoItem(props) {
return (
/**
* Let's make it so our checkbox can actually mark our todo as complete or incomplete!
* This challenge is a little more involved than some of the past ones. Check the comments
* in the code for some help on accomplishing this one
*
* Challenge:
* 1. Create an event handler in the App component for when the checkbox is clicked (which is an `onChange` event)
* a. This method will be the trickest part. Check the comments in the stubbed-out method below for some pseudocode to help guide you through this part
* 2. Pass the method down to the TodoItem component
* 3. In the TodoItem component, make it so when the `onChange` event happens, it calls the `handleChange` method and passes the id of the todo into the function
*/
import React from "react"
import TodoItem from "./TodoItem"
import todosData from "./todosData"
class App extends React.Component {
constructor() {
super()
this.state = {
todos: todosData
}
this.handleChange = this.handleChange.bind(this)
}
handleChange(id) {
// Update state so that the item with the given id flips `completed` from false to true (or vise versa)
// Remember not to modify prevState directly, but instead to return a new version of state with the change you want included in that update. (Think how you might use the `.map` method to do this)
this.setState(preState => {
const updateTodos = preState.todos.map(todo =>{
if(todo.id===id){
return {
...todo,
completed: !todo.completed
}
}
return todo
})
return{
todos: updateTodos
}
})
}
render() {
const todoItems = this.state.todos.map(item => )
return (
{todoItems}
)
}
}
export default App
TodoItem.js
import React from "react"
function TodoItem(props) {
return (
componentDidMount() {
// GET the data I need to correctly display
}
componentWillReceiveProps(nextProps) {
if (nextProps.whatever !== this.props.whatever) {
// do something important here
}
}
shouldComponentUpdate(nextProps, nextState) {
// return true if want it to update
// return false if not
}
componentWillUnmount() {
// teardown or cleanup your code before your component disappears
// (E.g. remove event listeners)
}
25.lesseon 39
// https://scrimba.com/g/greacthooks
App.js
// https://scrimba.com/g/greacthooks
// Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
import React from "react"
import randomcolor from "randomcolor"
class App extends React.Component {
constructor() {
super()
this.state = {
count: 0,
color: ""
}
this.increment = this.increment.bind(this)
this.decrement = this.decrement.bind(this)
}
increment() {
this.setState(prevState => {
return {
count: prevState.count + 1
}
})
}
decrement() {
this.setState(prevState => {
return {
count: prevState.count - 1
}
})
}
componentDidUpdate(prevProps, prevState) {
if(prevState.count !== this.state.count) {
const newColor = randomcolor()
this.setState({color: newColor})
}
}
render() {
return (
{this.state.count}
)
}
}
export default App
26.lesson 40
conditional.js
import React from "react"
function Conditional(props) {
return (
You have {this.state.unreadMessages.length} unread messages!
}
)
}
}
export default App
28.lesson 42
App.js
import React from "react"
/*
Challenge:
Given a stateless functional component:
1. Follow the steps necessary to add state to it,
// class-based component
// constructor method
2. Have state keep track of whether the user is logged in or not
// isLoggedIn: Boolean (true or false)
3. Add a button that logs the user in/out
// event listener (onClick)
a. extra challenge - make the button display "log in" if they're not logged in and "log out" if they are
// Conditional Rendering
4. Display text that says "Logged in" if the user is logged in, or "Logged out" if they're not.
// Conditional Rendering
*/
class App extends React.Component {
constructor() {
super()
this.state = {
isLoggedIn: false
}
this.handleClick = this.handleClick.bind(this)
}
handleClick() {
this.setState(prevState => {
return {
isLoggedIn: !prevState.isLoggedIn
}
})
}
render() {
let buttonText = this.state.isLoggedIn ? "LOG OUT" : "LOG IN"
let displayText = this.state.isLoggedIn ? "Logged in" : "Logged out"
return (
{displayText}
)
}
}
export default App
29.lseeon 43
todoItem.js
/**
* Challenge: Style the completed todo items differently from the incomplete items.
*/
import React from "react"
function TodoItem(props) {
const completedStyle = {
fontStyle: "italic",
color: "#cdcdcd",
textDecoration: "line-through"
}
return (
import React, {Component} from "react"
/**
* Challenge: Wire up the partially-finished travel form so that it works!
* Remember to use the concept of controlled forms
* https://reactjs.org/docs/forms.html
*
* All information should be populating the text below the form in real-time
* as you're filling it out
*
* This exercise is adapted from the V School curriculum on vanilla JS forms:
* https://coursework.vschool.io/travel-form/
*
* All of our challenges and learning resources are open for the public
* to play around with and learn from at https://coursework.vschool.io
*/
class App extends Component {
constructor() {
super()
this.state = {
firstName: "",
lastName: "",
age: "",
gender:"",
destination:"",
isVegan:false,
isKosher:false,
isLactoseFree:false
}
this.handleChange=this.handleChange.bind(this)
}
handleChange(event){
const {name, value,type,checked} = event.target
type==="checkbox" ? this.setState({
[name]:checked
})
:
this.setState({
[name]: value
})
}
render() {
return (
Entered information:
Your name: {this.state.firstName}{this.state.lastName}
本篇文章重点说明什么是函数柯里化,这个语法现象的背后动机是什么,有什么样的应用场景,以及与部分应用函数(Partial Applied Function)之间的联系 1. 什么是柯里化函数
A way to write functions with multiple parameter lists. For instance
def f(x: Int)(y: Int) is a
ApplicationContext能读取多个Bean定义文件,方法是:
ApplicationContext appContext = new ClassPathXmlApplicationContext(
new String[]{“bean-config1.xml”,“bean-config2.xml”,“bean-config3.xml”,“bean-config4.xml
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information re
参考了
http://zhedahht.blog.163.com/blog/static/25411174201142733927831/
但是用java来实现有一个问题。
由于Java无法像C那样“传递参数的地址,函数返回时能得到参数的值”,唯有新建一个辅助类:AuxClass
import ljn.help.*;
public class BalancedBTree {
BeanUtils.copyProperties VS PropertyUtils.copyProperties
作为两个bean属性copy的工具类,他们被广泛使用,同时也很容易误用,给人造成困然;比如:昨天发现同事在使用BeanUtils.copyProperties copy有integer类型属性的bean时,没有考虑到会将null转换为0,而后面的业