useTexture
Render a React element as a texture:Parameters
| Name | Type | Description |
|---|---|---|
| element | ReactElement | React element to render |
| size | SkSize | Texture size { width, height } |
| deps | DependencyList | Dependencies for re-rendering |
Use Cases
Complex Graphics as Textures
Render complex graphics once and reuse as textures:Animated Textures
Animate textures with transforms:Texture with Dependencies
Re-render texture when dependencies change:usePictureAsTexture
Convert aSkPicture to a texture:
useImageAsTexture
Use an image as a texture with automatic conversion:Performance Benefits
Rendering Complex Graphics Once
Textures are rendered once and cached:Reusing Graphics
Textures can be reused multiple times efficiently:Texture Filters
Apply filters to textures:Platform Considerations
Web Platform
On web, textures are automatically converted to non-texture images for compatibility:Memory Management
Textures consume GPU memory. Clean up when no longer needed:Common Patterns
Texture Atlas
Combine multiple graphics into a single texture:Cached Rendering
Cache expensive rendering operations:Limitations
- Textures are rendered at a fixed size
- Re-rendering requires re-creating the texture
- GPU memory usage increases with texture count
- Not suitable for frequently changing content
Best Practices
- Use textures for complex, static graphics
- Reuse textures when rendering the same graphic multiple times
- Specify dependencies to control when textures update
- Keep texture sizes reasonable to manage memory
- Prefer direct rendering for simple shapes
- Clean up textures when components unmount
Related
- Animations Overview - Animation fundamentals
- Reanimated Integration - Shared values and worklets
- Images - Working with images
- Offscreen Rendering - Render to offscreen surfaces