При загрузке приложения, скрипты из "what" выполняются сразу, чего быть не должно.
<Button className="def_btn" size="xl" level="2" onClick={tt("dsdd")}>
<Button className="def_btn" size="xl" level="2" onClick={() => tt("dsdd")}>
handler = () => {
tt("dsdd");
};
<Button className="def_btn" size="xl" level="2" onClick={this.handler}>
<Button size="sm" type="outline" color="danger" />
const StyledButton = styled.button`
height: ${props => props.height.sm}px;
${media.md`
height: ${props => props.height.md}px;
`}
${media.lg`
height: ${props => props.height.lg}px;
`}
`;
const getHeightProp = size => {
switch(size) {
case 'sm':
return { ... };
case 'md':
return {
sm: 32,
md: 48,
lg: 64,
};
case 'lg':
return { ... };
}
};
const Button = ({ size }) => {
return <StyledButton height={getHeightProp(size)} />;
}
getUsers = () => {
const { dispatch } = this.props;
fetch(`https://api.github.com/search/users?q=Donetsk`)
.then(res => res.json())
.then(res => {
return Promise.all(
res.items.map(user => fetch(`https://api.github.com/users/${user.login}`).then(res => res.json()))
).then(users => {
dispatch({ type: 'GET_USERS', users });
});
});
};
import React, { Component } from 'react';
import Child from './Child';
class Parent extends Component {
childRef = React.createRef();
render() {
return (
<Child innerRef={this.childRef} />
);
}
}
import React, { Component } from 'react';
export default class Child extends Component {
render() {
const { innerRef } = this.props;
return (
<div ref={innerRef}></div>
);
}
}
prevState => ({
counter: prevState.counter + 1,
counter: prevState.counter + 1,
})
prevState.counter === 0
, будет создаваться как:{
counter: 0 + 1,
counter: 0 + 1, // результат этого выражения попадет в созданный объект
}
{ counter: 1 }
window._rutarget = [];
window._rutarget.push({ 'event': 'showOffer' });
window._rutarget = [];
const AdService = {
showOffer() {
window._rutarget.push({'event': 'showOffer'});
},
};
export default AdService;
class Example extends React.Component {
componentDidMount() {
const { fetchComments, productSlug } = this.props;
fetchProductCommentsBySlug(productSlug);
}
handleRemoveComment = id => {
this.props.removeProductCommentById(id);
};
handleSubmitComment = e => {
// ...
this.props.postProductComment(productComment);
};
render() {
const { comments, users } = this.props;
// ...
}
}
const mapStateToProps = state => ({
users: usersSelector(state),
comments: commentsSelector(state),
});
const mapDispatchToProps = {
fetchProductCommentsBySlug,
removeProductCommentById,
postProductComment,
};
connect(mapStateToProps, mapDispatchToProps)(Example);
{
product_id: "223af-b4535-54e21-31233-12a122-b453d",
quantity: 2.
}
const Hat = ({ match }) => {
// ...
useEffect(() => {
fetch(`https://foo0022.firebaseio.com//male/hat.json`)
.then(res => res.json())
.then(setArrProd);
}, [match.url]);
// ...
}
<Link to={`/${item.anchor}`}>
<Link to={'/' + item.anchor}>
{this.state.cinemas.map(cinema => <ListItemCinema key={cinema.id} cinema={cinema} />)}
const ListItemCinema = ({ cinema }) => {
const { subway, shortTitle, labels, title, mail } = cinema.attributes;
/* some code */
return (
<div>
{/* some code */}
<ul>
{subway.map(station => <li key={station.name}>{station.name}</li>)}
</ul>
</div>
);
}
<Switch>
<Route path={"/"} exact render={() => <div>'100'</div>} />
<Route path={"/male/hat"} exact component={ProductsList} />
<Route path={"/male/hat/:to"} exact component={ProductDetails} />
</Switch>
const ProductDetails = ({ match }) => {
const { to } = match.params;
const [state, setState] = useState({ isFetching: true, hat: null });
const { isFetching, product } = state;
useEffect(() => {
(async () => {
await fetch(`https://foo0022.firebaseio.com//male/hat.json`)
.then(res => res.json())
.then(data => {
const product = data.find(item => item.to === to);
setState({ isFetching: false, product });
});
})();
}, []);
if (isFetching) return <div>...Loading</div>;
if (!product) return <div>404: Product not found</div>;
return (
<div>
<h1>{product.title}</h1>
<h2>{product.price}</h2>
</div>
);
}
const ProductsList = () => {
const [state, setState] = useState({ isFetching: true, products: [] });
const { isFetching, products } = state;
useEffect(() => {
(async () => {
await fetch(`https://foo0022.firebaseio.com//male/hat.json`)
.then(res => res.json())
.then(data => setState({ isFetching: false, products: data });
})();
}, []);
if (isFetching) return <div>...Loading</div>;
return (
<ul>
{products.map(({ to, title }) => (
<li key={to}>
<Link to={`/male/hat/${to}`}>{title}</Link>
</li>
))}
</ul>
);
};