<script>window.__INITIAL_STATE__ = { ... }</script>
Как я понял нужно для начала спарсить все в хранилище и потом уже работать с ним?
GET '/api/users?limit=20&sort=name&page=3
{
users: [ ... ],
page: 3,
limit: 20,
quantity: 450,
}
return возращает в скобках html код
render() {
return (
<h1 className="greeting">
Hello, world!
</h1>
);
}
render() {
return React.createElement(
'h1',
{ className: 'greeting' },
'Hello, world!'
);
}
{
$$typeof: Symbol(react.element),
key: null,
props: { className: "greeting", children: "Hello, world!" },
ref: null,
type: "h1",
_owner: null,
_store: { validated: false },
_self: null,
_source: null,
__proto__: Object,
}
React компилятор перед сборкой парсит данные в файлах компонентов...
...Я понимаю что реакт собирает все в ES2015...
или же это нормально для ES6
<Form>
<DatePicker />
<DatePicker />
<Divider />
<CheckBox />
<CheckBox />
<CheckBox />
<Divider />
<Input />
<TextArea />
<Button />
</Form>
<Form>
<DateFromToSelector />
<FormCheckboxes />
<Texts />
<Button />
</Form>
const someCall = () => async dispatch() => {
dispatch({type: Constant.SOME_OPERATION_1});
await dispatch(createAccount());
dispatch({type: Constant.SOME_OPERATION_2});
};
export const createAccount = () => async (dispatch) => {
await request api;
dispatch({type: SMTH});
await another request api;
dispatch({type: SMTH2});
}
export const createAccount = () => async (dispatch) => {
try {
await request api;
dispatch({type: SMTH});
await another request api;
dispatch({type: SMTH2});
catch (e) {
// handle error here
}
}
public onRoute = () => {
if (data.role_type === `/${document.location.pathname.split('/')[1]}`) {
return <Component/>; // тут ничего не передается
}
return this.context.router.history.push('/404');
}
public onRoute = () => {
if (data.role_type === `/${document.location.pathname.split('/')[1]}`) {
return <Component {...this.props} />;
}
return this.context.router.history.push('/404');
}
<AuthRoute path='/some_path' component={SomeComponent} />
const Grid = React.forwardRef((props, ref) => (
<div ref={ref}>{props.children}</div>
));
export class MyComponent extends React.Component {
render() {
return (
<Grid innerRef={this.props.forwardRef} />
);
}
}
const Grid = props => (
<div ref={props.innerRef}>{props.children}</div>
);
this.state.data[this.state.id][e.target.name] = !checked;
this.setState({
data: this.props.data,
id: this.props.id
});
const a = { key: 'value' };
const b = a;
b.key = 'new value';
console.log(a.key); // new value
this.state.data[this.state.id][e.target.name] = !checked;
render () {
const { match: { url } } = this.props;
return (
<Switch>
<Route exact path={url} content={Tweets} />
<Route exact path={url + '/with-replies'} content={WithReplies} />
<Route exact path={url + '/media'} content={Media} />
</Switch>
)
}
render() {
return someCondition ? (
<Component
prop1={a.prop1}
prop2={a.prop2}
prop3={a.prop3}
prop4={a.prop4}
prop5={a.prop5}
/>
) : (
<Component
prop1={b.prop1}
prop2={b.prop2}
prop3={b.prop3}
prop4={b.prop4}
prop5={b.prop5}
/>
);
}
render() {
const c = someCondition ? a : b;
return (
<Component
prop1={c.prop1}
prop2={c.prop2}
prop3={c.prop3}
prop4={c.prop4}
prop5={c.prop5}
/>
);
}
render() {
return (
<Wrapper>
{condition1 &&
condition2 &&
condition3 &&
condition4 && (
<Component />
)}
</Wrapper>
)
}
render() {
const shouldShowComponent = condition1 && condition2 && condition3 && condition4;
return (
<Wrapper>
{shouldShowComponent && <Component />}
</Wrapper>
);
}
handleNoteDel = index => {
const notes = [...this.state.notes];
notes.splice(index, 1);
this.setState({ notes });
}
handleNoteDel = index => {
this.setState({
notes: this.state.notes.filter((_, i) => i !== index),
});
}
import { render } from 'react-dom';
import {createStore} from "redux";
import rootReducer from "../reducers";
import Auth from './components/Auth';
const store = createStore(rootReducer);
render(
<Provider store={store}>
<BrowserRouter>
<Auth />
</BrowserRouter>
</Provider>,
document.getElementById('root'),
);
import React, {Component} from 'react';
import {connect} from 'react-redux';
class Auth extends Component {
render() {
return (
<Switch>
<Route exact path={this.props.api.signin} render={() => Test}/>
</Switch>
);
}
}
const mapStateToProps = state => ({
api: state.api,
});
export default connect(mapStateToProps)(Auth);
getPromoUrl = async (id, param) => {
const data = await this.getPromise(id, param);
console.log(data);
this.setState({ data });
};
getPromoUrl = (id, param) => {
this.getPromise(id, param).then(data => {
console.log(data);
this.setState({ data });
});
};