open-index/open-npm huggingface dataset:
npm package: @rogerbf/echo-server
Description: create a server that responds with the request object
Author: rogerbf
Latest version: 1.0.0

# echo-server

Echo echo echo.

```javascript
import createServer from 'echo-server'

createServer({ type: `http` })
  .then(server => console.log(server.address().port))
  .catch(console.error)
```
npm package: @rogerbf/use-middleware
Description: a middleware hook
Author: Roger Berg Falk
Latest version: 1.0.1

# use-middleware

```javascript
const logActionMiddleware = (_, { updateActionLog }) => next => action => {
  updateActionLog(action)
  return next(action)
}

const Counter = () => {
  const [state, _dispatch] = React.useReducer((state, action) => {
    if (action === 'increment') {
      return state + 1
    } else if (action === 'decrement') {
      return state - 1
    } else {
      return state
    }
  }, 0)

  const [actionLog, setActionLog] = React.useState([])

  const updateActionLog = action => setActionLog([...actionLog, action])

  const dispatch = useMiddleware(
    { updateActionLog },
    logActionMiddleware,
    _dispatch,
  )

  return (
    <>
      <h1>Count: {state}</h1>
      <button onClick={() => dispatch('increment')}>+</button>
      <button onClick={() => dispatch('decrement')}>-</button>
      <ol>
        {actionLog.map((action, index) => (
          <li key={index}>{action}</li>
        ))}
      </ol>
    </>
  )
}
```