Image

Next Image, with Extra Stuff.

Next/Image has become quite powerful over the past few years.

For props, it accepts all the attributes of your typical img tag, in addition to some very useful custom props such as layout, priority, onLoad and blurDataUrl.

We highly recommend referencing their documentation regularly for more up to date information.

Because we upload our images to Sanity and fetch them from the CDN, we don't necessarily know the height and width of the image coming in.

To get around this, we wrap our Next Image in a relatively-positioned figure element, so we can leverage the layout='fill' property.

There is a type prop that we can use to alter the figure wrapper that accepts one of two values: static or fluid.

  1. Static - the default value. We use the padding-bottom hack to prevent any layout shifts when the image is first loaded.

  2. Fluid - this will make the figure element absolutely positioned.

In either case, we don't have to worry about modifying the actual image - it's filling whatever container we have!

💡
See something that is out of date or that could be improved?Please let the team know!1. You can create a Github issue2. Pull down the repo and create a PR with your suggested changes implimented.3. Or just let someone know in the R&P Slack Channel.We love making things better.