SELECT Prop.*, coalesce("counters".countAllUnits, 0) AS "countAllUnits", coalesce("counters".countVacantUnits, 0) AS "countVacantUnits"
FROM "Property" AS Prop
INNER JOIN LATERAL
(
SELECT COUNT(*) AS countAllUnits,
count(*) filter(where "Unit".status = 'Vacant') as countVacantUnits
FROM "Unit"
WHERE Prop."id" = "Unit"."propertyId"
) AS "counters" ON true
WHERE Prop."userId" IN (
SELECT id FROM "User" WHERE "companyId" = 200001
)
ORDER BY Prop."userId" ASC LIMIT 10 OFFSET 0
const result = array.reduce((acc, el) => {
const key = 'Type' + el.type;
acc[key] = acc[key] ? [...acc[key], el] : [el];
return acc;
}, {});
И легально ли этим заниматься в редьюсере ? Может быть middleware лучше подойдет для этого?
shouldUpdate =
!shallowEqual(prevProps, nextProps) ||
!shallowEqual(inst.state, nextState);
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
The response had HTTP status code 403.
При нажатии на svg, event.target присваивается конкретным элементам - картинка внутри svg, текст, фигура итд.
event.target.closest('svg')
Допустим я нашел нужный эл-т, и вижу в console.log нужный атрибут, но если вызвать его напрямую, возвращается undefined
card.getAttribute('stroke')
onClickFuagra = () => {
this.setState({
strokeFuagra: '...',
});
}
onClickFish = () => {
this.setState({
strokeFish: '...',
});
}
<Samy svgXML={fuagra} onClick={this.onClickFuagra}>
...
</Samy>
<Samy svgXML={fish} onClick={this.onClickFish}>
...
</Samy>
onClick = e => {
const svg = e.target.closest('svg');
this.setState({
[имя свойства зависит от svg, как определить по кому был клик - думайте сами]: '...',
});
}
<div className="banners" onClick={this.onClick}>
...
Cannot convert undefined or null to object
import React from 'react';
import { connect } from 'react-redux';
export class Balance extends React.Component {
// some code
}
const mapStateToProps = ({ total }) => ({ total });
export default connect(mapStateToProps)(Balance);
import { Balance } from './Balance';
import Balance from './Balance';
import React from 'react';
import { shallow, mount } from 'enzyme';
import { expect } from 'chai';
import { Balance } from '../app/containers/balance/src/balance';
describe('<Balance />', () => {
it('Balance test', function () {
const mockTotal = { /* mock code */ };
const wrapper = shallow(<Balance total={mockTotal} />);
expect(wrapper.contains(<h3>Мои балансы</h3>)).to.equal(true);
});
});
import React, { Component } from 'react';
import { connect } from "react-redux";
class componentName extends Component {
render() {
const {minValue, maxValue} = this.props
return (
<div>
</div>
);
}
}
const mapStateToProps = (state, ownProps) => {
// здесь у вас есть доступ к redux store с вашим массивом данных
console.log('redux store ', state)
console.log('own component props ', ownProps)
const minVal = ваша функция
const maxVal = ваша функция
return {
minValue: minVal,
minValue: maxVal,
};
};
export default connect(mapStateToProps)(componentName);
var some = 5;
var str = 'I have:' + some + 'apples';
let some = 5;
let str = `I have ${some} apples`;
import { submit } from './actions'
...
onSubmit = (credentials) =>
this.props.submit(credentials)
.then((res) => console.log(res))
.catch((err) => console.log(err))
...
export default connect(null, { submit })(ComponentName);
import api from './api';
export const handleSuccessResponse = (data) => ({
type: USER_LOGGED_IN,
data
})
export const submit = (credentials) =>
(dispatch) => api.request(credentials).then(responseData => dispatch(handleSuccessResponse(responseData)));
import axios from 'axios';
export default request: (credentials) => axios.post('/api/request', { credentials }).then(res => res.data)
const action = {name: 'Dima', payload: 30};
const state = {
...state,
[action.name]: action.payload
};