React
- 8 ответов
- 0 вопросов
8
Вклад в тег
if (window.matchMedia('(max-width: 700px)').matches) {
for (const linkElement of document.querySelectorAll('.order-project__more-details-btn')) {
linkElement.setAttribute('href', 'examples-foundation-640')
}
}
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"deploy": "npm run build && gh-pages -d dist"
}
const dateA = new Date('...')
const dateB = new Date('...')
// разница в секундах с точностью до миллисекунды
const differenceInSeconds = (dateA.getTime() - dateB.getTime()) / 1000
// затем можно или отбросить дробную часть
console.log(Math.trunc(differenceInSeconds))
// или округлить одним из методов
console.log(Math.round(differenceInSeconds))
let lastReqDate
app.get('/api/v1/example', (req, res) => {
const date = new Date()
let diff
if (lastReqDate != null) {
diff = (date.getTime() - lastReqDate.getTime()) / 1000
}
if (diff != null && diff < 120) {
diff = Math.ceil(diff) // округление до ближайшего большего целого
res.header('Retry-After', diff)
res.status(429) // Too Many Requests
res.send({ retryAfter: diff })
} else {
lastReqDate = date
// выполнение запроса разрешено
}
})
class Lectures extends React.PureComponent {
state = {
lectures: null,
lecturesError: null,
lecturesPending: true,
}
async componentDidMount() {
await this.fetchLectures()
}
async fetchLectures() {
this.setState({ lectures:null, lecturesError:null, lecturesPending:true })
try {
const lectures = (await firebase.database().ref('lectures').once('value')).val()
console.log(lectures)
this.setState({ lectures, lecturesError:null, lecturesPending:false })
} catch (lecturesError) {
console.error(lecturesError)
this.setState({ lectures:null, lecturesError, lecturesPending:false })
}
}
render() {
const { lectures, lecturesError, lecturesPending } = this.state
return (
<section>
<h1>Лекции</h1>
{lecturesPending && (
<div>Загружаются...</div>
)}
{lecturesError != null && (
<div>Не удалось загрузить: {lecturesError.message}</div>
)}
{lectures != null && (
<ul>
{lectures.map((lecture) => (
<li
key={lecture.id}
>
{lecture.name}
</li>
))}
</ul>
)}
</section>
)
}
}