
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@schibstedspain/sui-react-hooks
Advanced tools
Useful hooks to be used in your React projects
$ npm install @schibstedspain/sui-react-hooks --save
Hook that will be executed when the component mounts. Similar behaviour to old componentDidMount
but useMount
could return a function that will executed when the component unmounts. Useful for clearing events or timers.
import { useMount } from '@schibstedspain/sui-react-hooks'
export default () => {
useMount(() => {
window.analytics.track('component did mount!')
})
useMount(() => {
const onScroll = () => console.log('scrolling')
document.addEventListener('scroll', onScroll)
return () => document.removeEventListener('scroll', onScroll)
})
const [currentUser, setCurrentUser] = useState(null)
useMount(async () => {
const user = await getUser()
setCurrentUser(user)
})
return currentUser && <h1>Hello {currentUser.name} !!</h1>
}
Hook to detect if an element is on the screen. Useful for lazy loading components, images or fetching of data.
You could configure if it should only be fired once
by using the parameter with the same name (default: true
).
import { useOnScreen } from '@schibstedspain/sui-react-hooks'
export default () => {
const [isIntersecting, outerRef] = useOnScreen({ once: true })
const [isIntersectingBlock, outerRefBlock] = useOnScreen({ once: false })
return (
<div ref={outerRef}>
{isIntersecting && <img src='huge-image.png' />}
<div>
</div>
)
}
Similar to useOnScreen
but it let you configure when the distance is enough to return true. By default if the element is 200px near the screen it will change the inner state of the hook. You could define the offset
in pixels to fire the event sooner or later.
import { useNearScreen } from '@schibstedspain/sui-react-hooks'
export default () => {
const [isNear, outerRef] = useNearScreen({ offset: '300px' })
return (
<div ref={outerRef}>
{isNear && <p>This is 300px near to the viewport!</p>}
<div>
</div>
)
}
Hook that provides a similar state management approach to the old this.setState
from a class.
Useful to cover quick functional migrations in components with complex states that would cause unnecessary renders if simply divided into lots of useState hooks.
If you apply this when migrating to a functional component, please take in mind that you may later rethink the strategy of its state.
import {useLegacyState} from '@schibstedspain/sui-react-hooks'
export default () => {
const initialState = {
availableFood: 20,
catsFood: 0,
dogsFood: 0
}
const [state, setState] = useLegacyState(initialState)
const {availableFood, catsFood, dogsFood} = state
const giveCatsFood = () => {
if (availableFood >= 2)
setState({
availableFood: availableFood - 2,
catsFood: catsFood + 2
})
}
const giveDogsFood = () => {
if (availableFood >= 2)
setState({
availableFood: availableFood - 2,
dogsFood: dogsFood + 2
})
}
const giveFoodToAll = () => {
if (availableFood >= 2)
setState({
availableFood: availableFood - 2,
catsFood: catsFood + 1,
dogsFood: dogsFood + 1
})
}
return (
<div>
<header>Available food: {availableFood || 'No more!'}</header>
<button onClick={giveCatsFood}>Give cats food</button>
<button onClick={giveDogsFood}>Give dogs food</button>
<button onClick={giveFoodToAll}>Give food to all</button>
<ul>
<li>Cats had {catsFood} of food.</li>
<li>Dogs had {dogsFood} of food.</li>
</ul>
</div>
)
}
Find full description and more examples in the demo page.
FAQs
> Useful hooks to be used in your React projects
The npm package @schibstedspain/sui-react-hooks receives a total of 1 weekly downloads. As such, @schibstedspain/sui-react-hooks popularity was classified as not popular.
We found that @schibstedspain/sui-react-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.