function pagination() {
function __construct() {
const NotAccess = (props) => {
return (
<div>
Доступ закрыт
</div>
)
}
export default class RouteAdmin extends React.Component {
constructor (props) {
super(props)
this.state = {
component: null
}
}
componentDidMount () {
axios.post('/admin').then(data => data.data).then(data => {
if (data.auth === true) {
const Admin = React.lazy(() => import('./moduleAdmin/Index'))
this.setState({component: Admin})
} else {
this.setState({component: NotAccess})
}
})
}
render () {
const Component = this.state.component
return (
<Route path="/admin" {...this.props} render={this.state.component}/>
)
}
}
<Route path='/admin' render={props => <RouteAdmin {...path} />} />
createItem(task) {
this.setState(prevState => ({
tasks: [
...prevState.tasks,
{ name: task, status: false },
],
}));
}
static getDerivedStateFromProps(props, state) {
if (props.data !== state.data) {
return {
data: props.data,
};
}
return null;
}
render() {
return(
<Wrapper>
<Header />
<Main />
<Footer />
</Wrapper>
);
}
const MainPageLayout = ({ children }) => (
<Wrapper>
<Header />
<PageContent>
{children}
</PageContent>
<Footer />
</Wrapper>
);
const SomePage = () => (
<MainPageLayout>
{/* page code */}
</MainPageLayout>
);
<Provider>
<Router>
<App />
</Router>
</Provider>
this.state = {...props}
this.state.props.foo
, можно будет обращаться через this.props.foo
.data.goals[0].gs_id
export default class Forma extends React.Component {
constructor(props) {
super(props);
this.state ={ data: {}, isFetching: true, error: null };
}
componentDidMount() {
fetch('http://localhost:3001')
.then(response => response.json())
.then(result => this.setState({data: result, isFetching: false }));
.catch(e => {
console.log(e);
this.setState({data: result, isFetching: false, error: e }));
});
}
render() {
const { data, isFetching, error } = this.state;
if (isFetching) return <div>...Loading</div>;
if (error) return <div>{`Error: ${e.message}`}</div>;
return <h1>{data.goals[0].gs_id}</h1>;
}
}
ref={ this.input }
this.setState({
showForm: true
}, () => {
console.log(this.input);
});