# @react-vertex/attribute-hooks

> React hooks for WebGL attributes

Latest version **1.2.0** (published 2019-04-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @react-vertex/attribute-hooks
pnpm add @react-vertex/attribute-hooks
yarn add @react-vertex/attribute-hooks
bun add @react-vertex/attribute-hooks
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-04-20 |
| First published | 2019-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1234 |
| Author | Steven Hall |
| Maintainers | sghall |
| Keywords | react, hooks, webgl |

## Links

- npm: https://www.npmjs.com/package/@react-vertex/attribute-hooks
- Repository: https://github.com/sghall/react-vertex
- Homepage: https://github.com/sghall/react-vertex/tree/master/packages/attribute-hooks#readme
- Issues: https://github.com/sghall/react-vertex/issues
- npm.io page: https://npm.io/package/@react-vertex/attribute-hooks

## Dependencies (2)

- [warning](https://npm.io/package/warning.md) ^4.0.3
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2019-04-20
- 1.1.0 — 2019-04-12
- 1.0.0 — 2019-04-08
- 0.4.0 — 2019-04-05
- 0.3.0 — 2019-04-04
- 0.2.0 — 2019-04-04
- 0.1.11 — 2019-03-29

## README

# `@react-vertex/attribute-hooks`

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/sghall/react-vertex/blob/master/packages/attribute-hooks/LICENSE)
[![bundlephobia](https://badgen.net/bundlephobia/minzip/@react-vertex/attribute-hooks)](https://bundlephobia.com/result?p=@react-vertex/attribute-hooks)
[![npm version](https://img.shields.io/npm/v/@react-vertex/attribute-hooks.svg)](https://www.npmjs.com/package/@react-vertex/attribute-hooks)

### [Documentation and Examples](https://react-vertex.com)

React hooks for working with WebGL attributes. More info on [WebGL atrributes on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer).

##### Install via npm:
```js
npm install @react-vertex/attribute-hooks
```

#### Importing:

```js
import {
  useAttribute
} from '@react-vertex/attribute-hooks'
```

## `useAttribute(gl, program, name, size, buffer, [getOptions])` => `index`

React hook for WebGL attributes.

##### Arguments:

`gl`: A WebGL context.

`program`: The [WebGLProgram](https://developer.mozilla.org/en-US/docs/Web/API/WebGLProgram) you want to attach the attribute to.

`name`: String name of the attribute used in the shader for the supplied program.

`size`: An integer indicating the number of components per vertex attribute. Must be 1, 2, 3, or 4.

`buffer`: A WebGL buffer. You can use hooks from `buffer-hooks` to create it.

`getOptions`: A function that will be called with the context (gl) that returns an object with the options you wish to override.

###### Valid keys in object returned by getOptions:
  - `target` defualts to gl.ARRAY_BUFFER
  - `type` defaults to gl.FLOAT
  - `normalized` defaults to false
  - `stride` defualts to 0
  - `offset` defaults to 0

##### Returns:

`index`: The index of the attribute.


##### Example Usage

```js
import { useStaticBuffer } from '@react-vertex/buffer-hooks'
import { useProgram } from '@react-vertex/shader-hooks'
import { useAttribute } from '@react-vertex/attribute-hooks'

const attrOptions = gl => ({
  type: gl.SHORT,
  stride: 20,
  offset: 16,
})

...
  const program = useProgram(gl, vert, frag)
  gl.useProgram(program)

  const myBuffer = useStaticBuffer(gl, position.array)
  useAttribute(gl, program, 'attrName', 3, myBuffer, attrOptions)
...

```

---
_Source: https://npm.io/package/@react-vertex/attribute-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
