const MyForm = () => {
const name = useSelector((state) => state.user.form.name);
const surname = useSelector((state) => state.user.form.surname);
const email = useSelector((state) => state.user.form.email);
const agree = useSelector((state) => state.user.form.agree);
...
}
const Field = ({ name, ... }) => {
const value = useSelector(...);
...
}
const MyForm = () => {
return (
<FormContainer ...>
<Field name="name"/>
<Field name="surname"/>
<Field name="email"/>
...
</Form>
)
}
square.forEach((el) => el.style.backgroundColor = 'green')
function replace($text, $word, $replacements) {
$r = $replacements;
$new_text = $text;
$replacement = null;
$pattern = "/$word/";
while(true) {
$replacement = $r[0];
$new_text = preg_replace(
$pattern,
$replacement,
$new_text,
1, // заменяем 1 раз
$count
);
if(!$count) return $new_text;
// ротируем замены
$r = array_merge(array_slice($r, 1), [$replacement]);
}
}
$replaced = replace(
"First word. Second word. Third word. Forth word.",
"word",
["apple", "banana", "watermelon"]
);
print_r($replaced);
// First apple. Second banana. Third watermelon. Forth apple.
@
и резолвятся в src/*
, попробуй добавить jsconfig.json в корень проекта с таким содержимым:{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"baseUrl": "./",
"paths": {
"@*": ["./src/*"]
}
},
"Include": ["./src/**/*"],
"exclude": ["node_modules", "build", "dist"]
}
add_to_array = 'InputMediaPhoto(' + str(id) + ')'
- вы просто записываете строку здесь, а должен быть вызов функции. При этом add_to_array не используется, append выполняется на каком-то array к тому же.bot.send_media_group(message.from_user.id, list(map(InputMediaPhoto, arrayID)))
if (todo.id === id) todo.completed = !todo.completed
return todo
Strict mode can’t automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following methods:
...
setState updater functions (the first argument)
...
if (todo.id === id) todo.completed = !todo.completed
это сайд-эффект.if (todo.id === id) return { ...todo, completed: !todo.completed }
It's very important that the reducer stays pure. Things you should never do inside a reducer:
Mutate its arguments;
Perform side effects like API calls and routing transitions;
Call non-pure functions, e.g. Date.now() or Math.random().
export function commentsReducer(state = {data: [], marker: false}, action) {
switch (action.type) {
case Comments.ADD_COMMENT: {
let newData = state.data.slice(); // копируем массив
newData.push({
postId: action.payload.postId,
body: action.payload.body,
name: action.payload.name,
id: state.data[state.data.length - 1].id + 1
});
// никакого state = ...
return {...state, is_fetching: false, data: newData};
}
}
return state;
}
const enumChildNodes = (node, acc = []) => {
if (node.children.length === 0) // дошли до последнего уровня
return acc.concat(`${node.tagName} ${node.innerText}`);
return acc.concat(
...[...node.children].map(node => enumChildNodes(node, acc))
)
}
enumChildNodes(document.body).forEach(item => console.log(item))
setStates(prev => {
prev.map(data => {
if (data.id === Number(id)) {
(data.state === 2) ? data.state = 0 : ++data.state
}
})
})
return prev.map...
if (data.id === Number(id)) {
(data.state === 2) ? data.state = 0 : ++data.state
}
[,,,{},]
data => {
if (data.id === Number(id)) {
return (data.state === 2) ? {...data, state: 0} : {...data, state: data.state + 1}
}
return data
}
() => expression
() => { return expression }
() => ({ someObjectField: ... })
const [nameValue, setNameValue] = useState(name || "");
<TextField
...
value={nameValue}
...
/>
const topics = [
{
topicName: 'Hello there',
messages: [{...}, {...}]
},
{
topicName: 'Need help',
messages: [{...}, {...}]
},
]
const msgIdx= topics.map(topic => topic.messages.map(msg => msg.id));
[ [], [], ...]
const msgIdx= topics.map(topic => topic.messages.map(msg => msg.id))
.reduce((acc, idList) => acc.concat(idList), [])
<Route path='/dialogue/:id' render={() => <DialogList />}/>
<Route path='/dialogue/:id' render={(props) => <DialogList {...props}/>}/>
newArray = [
...todoData.slice(0, idx),
...todoData.slice(idx + 1)
]
todoData.slice(0, idx).concat(todoData.slice(idx + 1))
$str = 'Иванов Иван Иванович 01.01.1970 353';
preg_match('/(\w*)\s(\w*)\s?(\w*)\s(\d\d\.\d\d.\d{4})\s(\d+)/u', $str, $match);
print_r($match);
function getOddList (count, current = 1, acc = []) {
if (count == 0) return acc;
return getOddList(count - 1, current + 2, acc.concat(current))
}
function getOddList (count) {
function iter(n, current, acc) {
if (n == count) return acc;
return iter(n + 1, current + 2, acc.concat(current))
}
return iter(0, 1, []);
}