// App.js
import React from 'react'
import './App.css'
import { BrowserRouter, Link, Switch, Route } from 'react-router-dom'
class Post extends React.Component {
componentDidMount() {
if (this.props.location.pathname === '/post/comments') {
this.scrollToComments()
}
}
componentDidUpdate() {
if (this.props.location.pathname === '/post/comments') {
this.scrollToComments()
}
}
scrollToComments() {
const element = document.querySelector('#comments')
element.scrollIntoView()
}
render() {
return (
<>
<h1>Post</h1>
<div>{new Array(100).fill(<p>long post</p>)}</div>
<h2 id='comments'>Comments</h2>
<div>{new Array(100).fill(<p>comment</p>)}</div>
</>
)
}
}
function App() {
return (
<BrowserRouter>
<div className='App'>
<nav>
<Link to='/post'>go to post</Link>
<Link to='/post/comments'>go to comments</Link>
</nav>
<main>
<Switch>
<Route path='/post' component={Post} />
{/*
other routes
*/}
</Switch>
</main>
</div>
</BrowserRouter>
)
}
export default App
Internally, React Redux uses React's "context" feature
const values = {
name: 'default',
year: '1999'
}
$("form").on("input",function(e){
if (values[e.target.id] != e.target.value) {
console.log("Есть");
} else {
console.log("Нет");
}
});
Math.max(...val.map(ar => ar.length))
Math.min(...val.map(ar => ar.length))