Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

Example of Sugar with create-react-app

Open rsweetland opened this issue 6 years ago • 5 comments

With the popularity of React (and create-react-app) these days, it would be great to see some examples of Sugar using it with webpack, es6 imports, etc.

rsweetland avatar Mar 15 '18 00:03 rsweetland

Awesome idea... will work on this soon!

andrewplummer avatar Mar 15 '18 01:03 andrewplummer

Thanks for the quick response here, Andrew! If you wouldn't mind giving a basic example even just in the comments here, I'd be happy to fill in implementation details. Minimally this thread should surface when people start searching for React with Sugar.

Something like this? npm install sugar

import Sugar from "sugar";
Sugar.Date.create('next Friday');  //wishful thinking..this doesn't seem to work

Btw, I just tested several js date parsing libs. Sugar's appears to be the best. Great work and thank you for building this!

rsweetland avatar Mar 15 '18 18:03 rsweetland

Here's a workaround in the meantime that plays nicely with Create React App:

Include the Sugar lib in your index.html

<script src="https://cdnjs.cloudflare.com/ajax/libs/sugar/2.0.4/sugar.min.js"></script>

Then, inside of Create React App, reference Sugar from the global, window object.

window.Sugar.Date.create('next Friday');

rsweetland avatar Mar 16 '18 22:03 rsweetland

Sorry for taking ages on this. The next major version of Sugar will be a complete refactor of the skeleton from the ground up to use ES6 imports. For now import * as Sugar from 'sugar' should work for you... let me know if it doesn't.

andrewplummer avatar Jul 28 '18 08:07 andrewplummer

Is there updated docs on how to use Sugar dates with React?

coltenkrauter avatar Jun 29 '20 16:06 coltenkrauter