Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div id="root">


                @import "";

#root > div > button {
  margin-bottom: 1rem;



                import React from "";
import ReactDOM from "";
import DatePicker from "";
import * as JsJodaCore from "";

const { ZonedDateTime, ChronoUnit } = JsJodaCore;

 * You don't need this, but it helps to make the example more clear
const FormattedErrorStack = (props) => {
  const { error } = props;
  if (!error) {
    throw new Error(`expected the error prop to be truthy`);

  const errorStr = error.stack ? error.stack : error.toString();

  return <div style={{ whiteSpace: "pre-line", color: "red" }}>{errorStr}</div>;

const CUSTOM_COMPONENT_NAME = "LocalDatePicker";
const LocalDatePicker = (props) => {
  const [error, setError] = React.useState(null);

  const convertToLocalDate = (d) => {
    try {
      var zdt = ZonedDateTime.parse(d.toISOString());
      var startOfDay = zdt.truncatedTo(ChronoUnit.DAYS);
    } catch (err) {

  if (error) {
    return (
        <h1>Error within {CUSTOM_COMPONENT_NAME}</h1>
          If you are seeing this then that means that {CUSTOM_COMPONENT_NAME} is
          not doing the conversion properly and that means that this example
          needs to be updated. Exact error message:
        <br />
        <FormattedErrorStack error={error} />

  return <DatePicker onChange={convertToLocalDate} preventOpenOnFocus={true} />;

class ErrorBoundary extends React.Component {
  constructor(props) {
    this.state = { error: null };

  static getDerivedStateFromError(error) {
    // Update state so the next render will show the fallback UI.
    return { error };

  componentDidCatch(error, errorInfo) {
    // You can also log the error to an error reporting service
    console.error(error, errorInfo);

  render() {
    if (!!this.state.error) {
      // You can render any custom fallback UI
      return (
          <h1>Something went wrong.</h1>
          <FormattedErrorStack error={this.state.error} />

    return this.props.children;

const App = () => {
  const [date, setDate] = React.useState(null);

  return (
      <LocalDatePicker onChange={setDate} />
      {!date ? (
        <h2>Please select a date</h2>
      ) : (
          <h2>Selected {CUSTOM_COMPONENT_NAME.replace("Picker", "")}</h2>
          <div>Year: {date.year().toString()}</div>
          <div>Month: {date.month().toString()}</div>
          <div>Day: {date.dayOfMonth().toString()}</div>
          <div>Minutes: not applicable</div>
          <div>Seconds: not applicable</div>

ReactDOM.render(<App />, document.getElementById("root"));