Installations
npm install react-native-web-hooks
Releases
Unable to fetch releases
Developer
evanbacon
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
16.13.0
NPM Version
8.1.0
Statistics
197 Stars
30 Commits
10 Forks
6 Watching
1 Branches
3 Contributors
Updated on 01 Jul 2024
Languages
TypeScript (98.23%)
JavaScript (1.77%)
Total Downloads
Cumulative downloads
Total Downloads
2,365,798
Last day
3.5%
3,909
Compared to previous day
Last week
11.5%
18,005
Compared to previous week
Last month
21%
69,001
Compared to previous month
Last year
31.2%
784,996
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
react-native-web-hooks
Hooks for implementing complex functionality in React Native for web and Expo.
A closer look at how the hooks work here.
Installation
1yarn add react-native-web-hooks 2 3or 4 5npm install --save react-native-web-hooks
Usage - Hooks
Import the library into your JavaScript file:
1import { 2 useDimensions, 3 useActive, 4 useFocus, 5 useHover, 6 useREM, 7 useScaledSize, 8} from 'react-native-web-hooks';
Get REM size
Use these in place of rem font sizes like: font-size: 1.3rem
.
Note: this isn't a hook anymore and will be moved out in the future.
1const fontSize = useREM(1.3); 2 3return <Text style={{ fontSize }} />;
Get scaled font size
These change based on the width of the screen.
1const fontSize = useScaledSize(1.5); 2 3return <Text style={{ fontSize }} />;
Get dimensions
Note that fontScale
is hard-coded to 1
on the react-native-web
side and shouldn't be used to calculate dynamic font sizes.
1const { 2 window: { width, height, fontScale, scale }, 3 screen, 4} = useDimensions();
Measure a view
It's best to style a view based on that own view's size and not the window size. To make this easier you can use the useLayout
hook!
🚨 Using
onLayout
may require you to installresize-observer-polyfill
. Learn more in the official Expo docs
1const { 2 onLayout, 3 width, 4 height, 5 x, 6 y 7} = useLayout(); 8 9return <View onLayout={onLayout} />
Create pseudo class styles
These will be replaced by React Flare when it's released.
1import { useRef } from 'react'; 2import { StyleSheet, Linking, Text, Platform } from 'react-native'; 3 4import { useHover, useFocus, useActive } from 'react-native-web-hooks'; 5 6function Link({ children, href = '#' }) { 7 const ref = useRef(null); 8 9 const isHovered = useHover(ref); 10 const isFocused = useFocus(ref); 11 const isActive = useActive(ref); 12 13 return ( 14 <Text 15 accessibilityRole="link" 16 href={href} 17 draggable={false} 18 onPress={() => Linking.openURL(href)} 19 tabIndex={0} 20 ref={ref} 21 style={[ 22 styles.text, 23 isHovered && styles.hover, 24 isFocused && styles.focused, 25 isActive && styles.active, 26 ]}> 27 {children} 28 </Text> 29 ); 30} 31 32const styles = StyleSheet.create({ 33 text: { 34 ...Platform.select({ 35 web: { 36 cursor: 'pointer', 37 outlineStyle: 'none', 38 borderBottomWidth: 1, 39 borderBottomColor: 'transparent', 40 transitionDuration: '200ms', 41 }, 42 default: {}, 43 }), 44 }, 45 active: { 46 color: 'blue', 47 borderBottomColor: 'blue', 48 opacity: 1.0, 49 }, 50 hover: { 51 opacity: 0.6, 52 }, 53 focused: { 54 borderBottomColor: 'black', 55 }, 56});
Usage - Render Props
Import the library into your JavaScript file:
1import { Hoverable, Resizable } from 'react-native-web-hooks';
You can wrap a function or a component.
1import React, { Component } from 'react'; 2import { Text, TouchableOpacity, View } from 'react-native'; 3import { Hoverable } from 'react-native-web-hooks'; 4 5const createLogger = (...msg) => () => { 6 console.log(...msg); 7}; 8 9class App extends Component { 10 render() { 11 return ( 12 <View> 13 <Hoverable onHoverIn={createLogger('start hover')} onHoverOut={createLogger('end hover')}> 14 {isHovered => ( 15 <TouchableOpacity accessible style={{ backgroundColor: isHovered ? '#333' : '#fff' }}> 16 <Text>Welcome to React</Text>} 17 </TouchableOpacity> 18 )} 19 </Hoverable> 20 </View> 21 ); 22 } 23}
Observe window resize events.
1return ( 2 <Resizable> 3 {layout => <View style={{ width: layout.width / 2, height: layout.width / 2 }} />} 4 </Resizable> 5);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/18 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Reason
70 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-22h7-7wwg-qmgg
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-f5x2-xv93-4p23
- Warn: Project is vulnerable to: GHSA-gmpm-xp43-f7g6
- Warn: Project is vulnerable to: GHSA-pf27-929j-9pmm
- Warn: Project is vulnerable to: GHSA-327c-qx3v-h673
- Warn: Project is vulnerable to: GHSA-x4cf-6jr3-3qvp
- Warn: Project is vulnerable to: GHSA-mph8-6787-r8hw
- Warn: Project is vulnerable to: GHSA-7mhc-prgv-r3q4
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-v8v8-6859-qxm4
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-4cpg-3vgw-4877
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-7f53-fmmv-mfjv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-gff7-g5r8-mg8m
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442
- Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-h6q6-9hqw-rwfv
- Warn: Project is vulnerable to: GHSA-5fg8-2547-mr8q
- Warn: Project is vulnerable to: GHSA-crh6-fp67-6883
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.9
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-web-hooks
react-native-device-info
Get device information using react-native
@react-native-community/hooks
![React Native Hooks](reactnativehooks.jpg)
babel-plugin-react-native-web
Babel plugin for React Native for Web
react-native-responsive-dimensions
Resposive fontSize, height and width for your react-native components.