Answer the question
In order to leave comments, you need to log in
How to properly pass the value value from one panel to another?
I have app.js, which contains two panels.
On one this code (excess removed):
const messages = [
{
values: [ [200,715],[717,749],[764,776],[800,999] ],
message: 'Выводится текст',
},
];
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const initialValue = "";
function Home() {
const [value, setValue] = React.useState(initialValue);
const addNumber = number => {
return () => {
setValue(prevValue => (prevValue + number).slice(0, 3));
};
};
const reset = () => {
setValue(initialValue);
};
return (
<div>
<div>
{messages
.filter(n => n.values.some(v => (
(v instanceof Array && v[0] <= value && value <= v[1]) ||
v === value
)))
.map(n => <div key>{n.message}</div>)
}
</div>
<div>
<input value={value} />
</div>
<div>
{numbers.map(number => (
<button key={number} onClick={addNumber(number)}>
{number}
</button>
))}
</div>
<div>
<button onClick={reset}>Clear</button>
</div>
</div>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question