This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 🐢 merge (setState) vs replace (useState) | |
// assume initial state is {name: "Ohans"} | |
setState({age: "unknown"}) | |
// new state object will be | |
// {name: "Ohans", age: "unknown"} | |
useState({age: "unknown"}) | |
// new state object will be | |
// {age: "unknown"} - initial object is replaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CounterHooks() { | |
const [count, setCount] = useState(0); | |
const [time, setTime] = useState(new Date()) | |
const handleClick = () => { | |
setCount(count + 1); | |
setTime(new Date()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CounterHooks() { | |
const [count, setCount] = useState(0); | |
const handleClick = () => { | |
setCount(count + 1); | |
} | |
return ( | |
<div> | |
<h3 className="center"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class Counter extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
count: 1 | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Web scraping in Node | |
const rp = require('request-promise'); | |
const cheerio = require('cheerio'); | |
const Table = require('cli-table'); | |
let table = new Table({ | |
head:['Username', '❣', 'challenges', 'Read', 'Visited','id'], | |
colWidths: [15, 5, 10, 9, 9, 9] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
submit = input=>{ | |
if(['Настя', 'Леша', 'Миша', 'Света'].includes (input.username)){ | |
throw new SubmissionError ({ | |
username : "Имя пользователя уже существует", | |
}); | |
}else{ | |
window.alert (JSON.stringify(input)) | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const requiredInput = (input) => | |
input ? undefined : `Требуется ввод`; | |
export const correctInput = input => | |
input !== 'Юрчик' ? 'Неправильное имя пользователя' : undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Fragment } from 'react'; | |
const myInput = (props) =>{ | |
const {input, type, placeholder, meta}=props; | |
return ( | |
<Fragment> | |
<input {...props.input} type={props.type} placeholder={props.placeholder}/> | |
{meta.error && | |
meta.touched && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const validate = inputs => { | |
const errors = {}; | |
if (!inputs.username) { | |
errors.username = 'Введите имя пользователя'; | |
} else if (inputs.username !== 'Юрчик') { | |
errors.username = 'Имя пользователя неверно'; | |
} | |
if (!inputs.password) { | |
errors.password = 'Введите ваш пароль'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export const myInput = props => { | |
return ( | |
<input {...props.input} type={props.type} placeholder={props.placeholder} /> | |
); | |
}; |