Languages
[Edit]
PL

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

0 points
Created by:
Leen-Kerr
511

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);

Alternative titles

  1. React - przycisk, który wysy┼éa zapytanie AJAX
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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