const Amasia = () => (
<div>Amasia</div>
);
const Product = ({ match }) => (
<div>
Page number: {match.params.page}
</div>
);
const Header = () => (
<header>
<nav>
<Link to="/">Amasia</Link>
<Link to="/Mens/Hat/1">Product</Link>
</nav>
<div>Logo</div>
<div>FormSearch</div>
<div>ButSearch</div>
</header>
);
const App = () => (
<>
<Header />
<main>
<Switch>
<Route exact path="/" component={Amasia} />
<Route exact path="/Mens/Hat/:page" component={Product} />
</Switch>
</main>
</>
);
const rootElement = document.getElementById("root");
ReactDOM.render(
<Router>
<App />
</Router>,
rootElement,
);
public async handler(id: string, valueSearch: string) {
await this.request(id)
.then((array: faceProductList[]) => {
...
public async request(id: string): Promise<faceProductList[][]> {
const res = await fetch(`${this.url}${id}`);
const resArr: faceProductList[] | faceProductList[][] = await res.json();
if (resArr.length === 0) {
return resArr;
}
if (Array.isArray(resArr[0])) {
return resArr;
}
return [resArr];
}
useEffect(() => {
doSomething();
}, [match.params.id]);
с чем это связано
let s: string;
s = 182;
const [prod, setProd] = useState<FakeProductList | null>(null);
if (!prod) {
}
return (/* ... */);
import React, { FC, useEffect } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
interface OwnProps {
error: string;
}
type Props = OwnProps & RouteComponentProps<any>;
const HandlerErr: FC<Props> = ({ error, history }) => {
useEffect(() => {
const timeout = setTimeout(() => {
history.push(`/`);
}, 2000);
return () => {
clearTimeout(timeout);
};
}, [error]);
return (
<>
<div>{error}</div>
<div>Contact site administrator</div>
</>
);
};
export default withRouter(HandlerErr);
let x = "COTiynkTfM & Length = 1000251jink56516156" Finti: Ginjoko ";
const x = "Categories=All&Search=Filus";
const parseQueryString = str => str.split('&').reduce((acc, el) => {
const [key, value] = el.split('=');
acc[key] = value;
return acc;
}, {});
const params = parseQueryString(x);
console.log(params); // { Categories: "All", Search: "Filus" }
const values = Object.values(params);
console.log(values); // [ "All", "Filus" ]
const Hat = ({ match }) => {
// ...
useEffect(() => {
fetch(`https://foo0022.firebaseio.com//male/hat.json`)
.then(res => res.json())
.then(setArrProd);
}, [match.url]);
// ...
}
<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>
);
};
function getProperty() : ( Mansion & House) {
...
interface House {
bedrooms: number,
bathrooms: number
}
interface Mansion extends House {
butlers: number
}