1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React

Last updated at Posted at 2021-02-18

#自分用メモ

##ArrayにsetStateでデータを追加したい時
####pushではなくconcatを使う

          this.setState({
              myArray: this.state.myArray.concat(e.file.response.data)
          })

#Router

index.js
<Router>
    //初期画面
    <Route exact path="/" component={App} />
    //他の画面
    <Route path="/newPage" component={newPage} />
</Router>

##Componentから移動したいとき

app.js
this.props.history.push({
    pathname: "/newPage"
})

##編集しやすいため、ページリンクまとめ作るの推薦

PageRoute.js
const PAGEROUTE = {
    NEW_PAGE: "/newPage"
}
export default PAGEROUTE;
Router.js
const Routing = (
    <Router>
         ...省略
    </Router>
)
export default Routing;
index.js

import Routing from './Router';

render() {
    render(
        <div>
            <Routing />
        </div>
app.js
import PAGEROUTE from './PageRoute';

this.props.history.push({
    pathname: {PAGEROUTE.NEW_PAGE}
})
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?