Download react-redux-realworld-example-app/src/components/App.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/App.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/App.js
-
curl -L -o App.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/App.js
2.66 kB
| import agent from '../agent'; | |
| import Header from './Header'; | |
| import React from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { APP_LOAD, REDIRECT } from '../constants/actionTypes'; | |
| import { Route, Switch } from 'react-router-dom'; | |
| import Article from '../components/Article'; | |
| import Editor from '../components/Editor'; | |
| import Home from '../components/Home'; | |
| import Login from '../components/Login'; | |
| import Profile from '../components/Profile'; | |
| import ProfileFavorites from '../components/ProfileFavorites'; | |
| import Register from '../components/Register'; | |
| import Settings from '../components/Settings'; | |
| import { store } from '../store'; | |
| import { push } from 'react-router-redux'; | |
| const mapStateToProps = state => { | |
| return { | |
| appLoaded: state.common.appLoaded, | |
| appName: state.common.appName, | |
| currentUser: state.common.currentUser, | |
| redirectTo: state.common.redirectTo | |
| }}; | |
| const mapDispatchToProps = dispatch => ({ | |
| onLoad: (payload, token) => | |
| dispatch({ type: APP_LOAD, payload, token, skipTracking: true }), | |
| onRedirect: () => | |
| dispatch({ type: REDIRECT }) | |
| }); | |
| class App extends React.Component { | |
| componentWillReceiveProps(nextProps) { | |
| if (nextProps.redirectTo) { | |
| // this.context.router.replace(nextProps.redirectTo); | |
| store.dispatch(push(nextProps.redirectTo)); | |
| this.props.onRedirect(); | |
| } | |
| } | |
| componentWillMount() { | |
| const token = window.localStorage.getItem('jwt'); | |
| if (token) { | |
| agent.setToken(token); | |
| } | |
| this.props.onLoad(token ? agent.Auth.current() : null, token); | |
| } | |
| render() { | |
| if (this.props.appLoaded) { | |
| return ( | |
| <div> | |
| <Header | |
| appName={this.props.appName} | |
| currentUser={this.props.currentUser} /> | |
| <Switch> | |
| <Route exact path="/" component={Home}/> | |
| <Route path="/login" component={Login} /> | |
| <Route path="/register" component={Register} /> | |
| <Route path="/editor/:slug" component={Editor} /> | |
| <Route path="/editor" component={Editor} /> | |
| <Route path="/article/:id" component={Article} /> | |
| <Route path="/settings" component={Settings} /> | |
| <Route path="/@:username/favorites" component={ProfileFavorites} /> | |
| <Route path="/@:username" component={Profile} /> | |
| </Switch> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div> | |
| <Header | |
| appName={this.props.appName} | |
| currentUser={this.props.currentUser} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| // App.contextTypes = { | |
| // router: PropTypes.object.isRequired | |
| // }; | |
| export default connect(mapStateToProps, mapDispatchToProps)(App); | |