andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 306 forks source link

Example of Sugar with create-react-app #626

Open rsweetland opened 6 years ago

rsweetland commented 6 years ago

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.

andrewplummer commented 6 years ago

Awesome idea... will work on this soon!

rsweetland commented 6 years ago

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 commented 6 years ago

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');
andrewplummer commented 6 years ago

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.

coltenkrauter commented 4 years ago

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