Languages
[Edit]
PL

React - przycisk wysy┼éaj─ůcy zapytanie AJAX

0 points
Created by:
Leen-Kerr
241

Poni┼╝szy przyk┼éad pokazuje przycisk, kt├│ry wysy┼éa ┼╝─ůdanie GET po klikni─Öciu na przycisk.

// ONLINE-RUNNER:browser;

// Uwaga: Odkomentuj poni┼╝sze linijki podczas pracy z kompilatorem JSX:
// import React from 'react';
// import ReactDOM from 'react-dom';

const App = () => {
    const [response, setResponse] = React.useState();
    const handleClick = async () => {
        const text = "Jaki┼Ť tekst wewn─ůtrz...";
        try {
            const response = await fetch(`/examples/echo?text=${encodeURIComponent(text)}`);
            const responseText = await response.text();
            setResponse(`Response: ${responseText}`);
        } catch (error) {
          	setResponse("B┼é─ůd ┼╝─ůdania!");
        }
    };
    return (
      <div>
        <button onClick={handleClick}>Wy┼Ťlij ┼╝─ůdanie AJAX!</button>
        {response && <div>{response}</div>}
      </div>
    );
};

const root = document.querySelector("#root");
ReactDOM.render(<App />, root);

ReactJS (PL)

React - przycisk wysy┼éaj─ůcy ┼╝─ůdanie AJAX
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join