Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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.


Save Automatically?

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.






                import React, {useState, useEffect} from 'react';

import Card from '../card/card.component';

// in this example we are getting data from an API and displaying it to the user, who can type a query into a search field
const UseEffectExample = () => {
  if (searchQuery.length > 0) {
    //set the initial values
    const [user, setUser] = useState(null);
    const [searchQuery, setSearchQuery] = useState('');

    useEffect(() => {
      const fetchFunc = async () => {
        const response = await fetch(`${searchQuery}`);

        // convert the response to JSON     
        const resJson = await response.json();

        // in this case, the response is a an array, so using resJson[0] will return the first item of any response (or undefined/null if none)

    }, [searchQuery]); // place the property inside the array so that whenever the search query changes, call useEffect again
  return (
  // your UI code here