# react-native-comp-util

> Utility components for better react native development experience

Latest version **1.0.2** (published 2020-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-comp-util
pnpm add react-native-comp-util
yarn add react-native-comp-util
bun add react-native-comp-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-09-26 |
| First published | 2020-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | naeemur |
| Keywords | react-native, react native, comp, util |

## Links

- npm: https://www.npmjs.com/package/react-native-comp-util
- Repository: https://github.com/naeemur/react-native-comp-util
- Homepage: https://github.com/naeemur/react-native-comp-util#readme
- Issues: https://github.com/naeemur/react-native-comp-util/issues
- npm.io page: https://npm.io/package/react-native-comp-util

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-09-26

## README

# React Native Comp Util

Utility components for better react native development experience.

## Features
- Pure JS, lightweight, works on Android, iOS and Web
- Helpful development logging method for CLI in `__DEV__` environment only
- Easy jQuery like `ref` helper method
- Wrapper around `TouchableNativeFeedback` for iOS and Web

## Installation

```
npm install react-native-comp-util
```

## Usage

```js
import { Component } from 'react'
import { View, Text } from 'react-native'

import { Comp, Compact, TouchableNativeFeedback } from 'react-native-comp-util'

class FirstComp extends Compact {
	someMethod() {
		// console.log() but with some helpful formatting for development CLI
		this.log('FirstComp.someMethod() was called')
	}
	render() {
		// super.render() call will prevent this component from updating later on
		super.render()
		return (
			<Text>Hello First Comp</Text>
		)
	}
}

class SecondComp extends Comp {
	onPress = () => {
		this.$firstComp.someMethod()
		// or use this way
		// this.$('firstComp').someMethod()
	}
	render() {
		return (
			// TouchableWithoutFeedback will be used on iOS and Web
			<TouchableNativeFeedback
				onPress={this.onPress}
				background={TouchableNativeFeedback.Ripple(`rgba(0,0,0,0.32)`, false)}
			>
				<View>
					<Text>Hello Second Comp</Text>
					<FirstComp ref={this.$$('firstComp')} />
				</View>
			</TouchableNativeFeedback>
		)
	}
}

export default SecondComp
```

## API

### ***Comp***
This class extends React's `Component` class with some useful methods.

```ts
log(...messages:any)
```
It is a formatted development logging method which is only prints logs in development builds (when `__DEV__` is true) and it is just an empty function otherwise. format includes the name of the component class, equal gap before messages and a collapsed stack trace on the web devTools.

```ts
rerender()
```
It is a method that calls `forceUpdate()` on the component

```ts
$$(refName:String):function
```
It creates a reference of a component instance when used like `<View ref={this.$$('compName')}></View>` on the component

```ts
$(refName:String):ComponentInstance
```
It returns a reference of a component instance created by `$$('compName')` which can be used like `this.$compname.someMethod()` or like `this.$('compname').someMethod()`

```ts
_:Object
```
It contains the references created by `$$('compName')`

### ***Compact***
This class extends `Comp` class with 2 additional methods.

```ts
render()
```
It sets property `rendered = 1` and increments property `renderCount` by 1 and this method is to be used like `super.render()` in the implemented render method.

```ts
shouldComponentUpdate():Boolean
```
It checkes `rendered` property and returns false if it is not equal to zero, which will prevent the component from updating.

### ***TouchableNativeFeedback***
On iOS and Web, it extends React Native's `TouchableWithoutFeedback` with static methods like `Ripple()`, `SelectableBackground()`, `SelectableBackgroundBorderless()`, `canUseNativeForeground()` for compatibility with TouchableNativeFeedback usage.

## License
The MIT License (MIT)

Copyright (c) 2020 Md. Naeemur Rahman (https://naeemur.github.io)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

---
_Source: https://npm.io/package/react-native-comp-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
