Gathering detailed insights and metrics for react-native-web-hooks
Gathering detailed insights and metrics for react-native-web-hooks
Gathering detailed insights and metrics for react-native-web-hooks
Gathering detailed insights and metrics for react-native-web-hooks
npm install react-native-web-hooks
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
197 Stars
30 Commits
10 Forks
6 Watching
1 Branches
3 Contributors
Updated on 01 Jul 2024
TypeScript (98.23%)
JavaScript (1.77%)
Cumulative downloads
Total Downloads
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
3
Hooks for implementing complex functionality in React Native for web and Expo.
A closer look at how the hooks work here.
1yarn add react-native-web-hooks 2 3or 4 5npm install --save react-native-web-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';
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 }} />;
These change based on the width of the screen.
1const fontSize = useScaledSize(1.5); 2 3return <Text style={{ fontSize }} />;
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();
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} />
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});
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
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
70 existing vulnerabilities detected
Details
Score
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 Morereact-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.