Update example code to use React Class syntax (#16)

* Update to use React Class syntax

This is the recommended syntax to use now, and as such will be more familiar to beginners. :)

* Converted old requires to import statements.
This commit is contained in:
Ruben Martinez Jr
2017-06-12 03:02:20 -07:00
committed by Jason Salzman
parent 66d602884b
commit 17efec9b08
+17 -21
View File
@@ -20,29 +20,25 @@ npm install react-add-to-calendar --save
Youll need to install React and Moment separately since they are not included in the package. Below is a simple example on how to use the Add to Calendar button in a React view. Youll need to install React and Moment separately since they are not included in the package. Below is a simple example on how to use the Add to Calendar button in a React view.
```js ```js
var React = require('react'); import React from 'react';
var createReactClass = require('create-react-class'); import AddToCalendar from 'react-add-to-calendar';
var AddToCalendar = require('react-add-to-calendar');
var Example = createReactClass({ class Example extends React.Component {
displayName: 'Example', static displayName = 'Example';
state = {
event: {
title: 'Sample Event',
description: 'This is the sample event provided as an example only',
location: 'Portland, OR',
startTime: '2016-09-16T20:15:00-04:00',
endTime: '2016-09-16T21:45:00-04:00'
}
};
getInitialState: function() { render() {
return {
event: {
title: 'Sample Event',
description: 'This is the sample event provided as an example only',
location: 'Portland, OR',
startTime: '2016-09-16T20:15:00-04:00',
endTime: '2016-09-16T21:45:00-04:00'
}
};
},
render: function() {
return <AddToCalendar event={this.state.event}/>; return <AddToCalendar event={this.state.event}/>;
} };
}); }
``` ```
## Configuration ## Configuration
@@ -89,4 +85,4 @@ The examples are hosted within the docs folder and are ran in the simple add tha
## License ## License
Copyright (c) 2016-2017 Jason Salzman. Licensed under MIT license, see [LICENSE](LICENSE) for the full license. Copyright (c) 2016-2017 Jason Salzman. Licensed under MIT license, see [LICENSE](LICENSE) for the full license.