css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              const root = document.getElementById('root')
const bus = new Bulb.Bus()

// A signal that searches for books by ISBN and emits the result as a new state.
const searchSignal = bus
  // Don't bother searching for empty queries.
  .filter(a => a !== '')

  // Search for the book using the API.
  .concatMap(findBook)

  // Create a new state.
  .map(result => ({ result, loading: false }))

// A signal that emits a loading state while the request is processing.
const loadingSignal = bus.always({ result: null, loading: true })

// Start with the default state and re-render the view when the other signals emit values.
Bulb.Signal.of({ result: null, loading: false })
  .merge(searchSignal, loadingSignal)
  .subscribe(
    state => ReactDOM.render(<RootView bus={bus} loading={state.loading} result={state.result} />, root)
  )

// Returns a signal that emits the result of the search request to the API.
function findBook (isbn) {
  const url = `https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn}`
  return Bulb.Signal
    .fromPromise(fetch(url).then(response => response.json()))
    .map(
      data => data.totalItems > 0 ? data.items[0].volumeInfo.title : null
    )
}

function RootView ({ bus, loading, result }) {
  const [query, setQuery] = React.useState('')

  return (
    <div className='jumbotron jumbotron-fluid'>
      <div className='container'>
        <h1>Book Search 📚</h1>
        <p className='lead'>This example demonstrates using a signal to handle an AJAX request.</p>
        <p>Enter an ISBN to find on Google Books (e.g. 0747532699).</p>
        <div class='input-group mb-3'>
          <input className='form-control' onChange={event => setQuery(event.target.value)} placeholder='ISBN' type='text' />
          <div className='input-group-append'>
            <Button disabled={loading} onClick={() => bus.next(query)}>
              {loading ? <Spinner /> : null}
              Search
            </Button>
          </div>
        </div>
        {result ? <pre>{result}</pre> : null}
      </div>
    </div>
  )
}

function Button ({ children, disabled, onClick }) {
  return (
    <button className='btn btn-primary' disabled={disabled} onClick={onClick}>{children}</button>
  )
}

function Spinner () {
  return (
    <React.Fragment>
      <span className='spinner-grow spinner-grow-sm' role='status' aria-hidden='true'></span>
      &nbsp;
    </React.Fragment>
  )
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console