let iconRef;
const getIconRef = node => iconRef = node;
const IconsList = {
internet: (
<svg ref={getIconRef} width="22px" height="16px" viewBox="0 0 22 16" version="1.1">
/* ... */
</svg>
),
];
copyToClipboard = text => {
var textField = document.createElement("textarea");
textField.innerText = iconRef;
document.body.appendChild(textField);
textField.select();
document.execCommand("copy");
textField.remove();
};
import { renderToString } from 'react-dom/server';
textField.innerText = renderToString(/* иконка описанная JSX */);
app.post('/api/search', async function(req, res) {
var query = {}
var reserveNomersIds;
var filter = {}
//price
if (req.body.min && req.body.max) {
query.cost_per_night = {$gte: req.body.min, $lte: req.body.max}
//по возрастанию
filter.cost_per_night = 1
}
//dates
if (req.body.from && req.body.to) {
reserveNomersIds = await Reservation.distinct("nomer", {
from: {
$lt: new Date(req.body.to)},
to: {$gt: new Date(req.body.from)
}
});
}
if (req.body.guests > 1) {
query.occupancy = {$gte: req.body.guests}
}
if (req.body.search) {
query.city = { $regex: req.body.search.toLowerCase() }
}
try {
var result = await Nomer
.find({ _id: { $nin: reserveNomersIds}, query})
.sort(filter);
res.json(result);
} catch (e) {
res.send(e);
}
})
this.setState({ studios: res.data, isLoading: false })
this.setState({ max: this.state.studios.reduce((l, e) => (e.price > l.price ? e : l)) });
this.setState({ min: this.state.studios.reduce((l, e) => (e.price < l.price ? e : l)) });
this.setState({
studios: res.data,
isLoading: false,
max: res.data.reduce((l, e) => (e.price > l ? e.price : l), -Infinity),
min: res.data.reduce((l, e) => (e.price < l ? e.price : l), Infinity),
});
// или, без reduce'ов
const prices = res.data.map(n => n.price);
this.setState({
studios: res.data,
isLoading: false,
max: Math.max(...prices),
min: Math.min(...prices),
});