简体   繁体   中英

How do I add airbnb react-dates to my HTML page?

I would like to have the airbnb react-dates SingleDatePicker or DateRangePicker appear on my html page. What do I need to add to my html page to get this to function correctly? Which files do I need from the airbnb react-dates?

I am a designer with basic html and css knowledge and in the last few days, I went from zero percent javascript knowledge and never hearing of react, to learning about the basics and installing node.js/npm, using terminal for my first time ever, connecting to the server and being so close, but I still do not understand.

I just want to add a simple datepicker, something I can do in html/css/js in a few minutes, but this react thing is extremely confusing to me. Do I need to run the commands in terminal or can I just add some code to my html, with the airbnb react-dates files? I have tried many dozens of recommendations, asked questions on here and other sites, all without any success. Thank you for your help!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Please help me with airbnb react-dates!</title>
</head>
<body>
    <div id="root">
        I would like to have the <a href="https://github.com/airbnb/react-dates/">airbnb react-dates</a> SingleDatePicker or DateRangePicker here.
    </div>
</body>
</html>

Note: I am only including the html, because I do not know the other scripts needed from the airbnb react-dates link to get this to work.

Moving solution from the question to its own answer

I was able to get this to work using the like button example

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Add React in One Minute</title>
  </head>
  <body>

    <h2>Add React in One Minute</h2>
    <p>This page demonstrates using React with no build tooling.</p>
    <p>React is loaded as a script tag.</p>
    
    <!-- We will put our React component inside this div. -->
    
    <div id="datepicker"></div>
    
    <!-- Load React. -->
    <!-- Note: when deploying, replace "development.js" with "production.min.js". -->
    <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>

    <!-- Load our React component. -->
    <script src="datepicker.js"></script>

  </body>

    
</html>
'use strict';

const e = React.createElement;

class LikeButton extends React.Component {
  constructor(props) {
    super(props);
    this.state = { liked: false };
  }

  render() {
    if (this.state.liked) {
      return 'You liked this.';
    }

    return e(
      'button',
      { onClick: () => this.setState({ liked: true }) },
      'Like'
    );
  }
}

const domContainer = document.querySelector('#datepicker');
ReactDOM.render(e(LikeButton), domContainer);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM