function App() {
const [ startupData, setStartupData ] = React.useState([]);
React.useEffect(() => {
fetch('http://localhost:8080/api/v1/startup')
.then(res => res.json())
.then(data => setStartupData(data))
.catch(err => console.error('Err: ', err));
}, []);
if (startupData?.length === 0) {
return <h1>Loading...</h1>;
}
return (
<div>
<table border="2">
<thead>
<tr>
<td>startup_id</td>
<td>startup_name</td>
<td>startup_descr</td>
<td>startup_price</td>
</tr>
</thead>
<tbody>
{startupData?.map(startup => (
<tr key={startup.startup_id}>
<td>{startup.startup_id}</td>
<td>{startup.startup_name}</td>
<td>{startup.startup_descr}</td>
<td>{startup.startup_price}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
document.addEventListener('click', ({ target }) => {
const button = target.closest('.new-faq__answer-btn');
if (button) {
button.parentNode.querySelector('.new-faq__answer').classList.toggle('active');
button.childNodes[2].classList.toggle('active');
}
});
var clickId1 = document.getElementById('clickId1') // кнопка
var contentId1 = document.getElementById('contentId1') // контент
const myClass = 'contentClass2'
switch(localStorage.getItem('theme')) {
case myClass:
contentId1.classList.toggle(myClass)
}
clickId1.addEventListener('click', () => {
contentId1.classList.toggle(myClass)
if (contentId1.classList.contains(myClass)) {
localStorage.setItem('theme', myClass);
} else {
localStorage.removeItem('theme', myClass);
}
})
Note how our original code did not need to import React to use JSX anymore! (But we would still need to import React in order to use Hooks or other exports that React provides.)
useEffect(() => {
fetch("http://localhost:5001/xxx")
.then(data => data.json())
.then(response => setData(response))
.catch(error => console.log(error))
}, []);
<span v-if="ruleForm.isValid === false">
Текст ошибки
</span>
ruleForm: {
cars: [],
isValid: null,
carModels: {
toyota: true,
ferrari: false,
suzuki: false,
bmw: true
}
}
validateCars(formName) {
if (this.ruleForm.cars.length === 0) {
this.ruleForm.isValid = false;
} else {
this.ruleForm.isValid = true;
console.log('success');
}
}
React component names must start with an uppercase letter
InputTweet
const admins = data
.filter(n => n.rank === 'admin')
.reduce((acc, n) => {
acc += `${n.name} ${n.lastname}, `;
return acc;
}, '').trim().replace(/,$/, '.');
document.querySelector('.result').innerText =
[...document.querySelectorAll('.sum')].reduce((acc, n) => acc + +n.innerText, 0);
<div class="container pt-5" id="counter">
<div class="card center">
<h1> {{ counter }}</h1>
<div>
<button class="btn">+</button>
</div>
</div>
</div>