Capítulo 70 de 988

Chapter 70: staticFile()

Core Idea

Turns a file in your public/ folder into an URL which you can then load into your project.

Key Concepts

  • Example
  • Why can't I just pass a string?
  • Getting all files in the public folder
  • Handling URI-unsafe characters<AvailableFrom v="4.0.0"/>
  • Compatibility
  • See also

Code Examples

const myImage = staticFile(`/my-image.png`);

// ...

<Img src={myImage} />;
  • What it demonstrates: Usage pattern for staticFile() from the official docs.

Key Takeaways

  1. Understand example when working with staticFile().
  2. Understand why can't i just pass a string? when working with staticFile().
  3. Understand getting all files in the public folder when working with staticFile().
  4. Understand handling uri-unsafe characters<availablefrom v="4.0.0"/> when working with staticFile().
  5. Understand compatibility when working with staticFile().

Connects To

  • Cancel Render: related page in the Hooks & Data APIs section.
  • Continue Render: related page in the Hooks & Data APIs section.
  • Data Fetching: related page in the Hooks & Data APIs section.