New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rbxts/react-reflex

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rbxts/react-reflex

Hooks for Reflex and React TS

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92
decreased by-31.85%
Maintainers
1
Weekly downloads
 
Created
Source

Reflex
React Reflex

GitHub Workflow Status npm version npm downloads GitHub license


 

♻️ Reflex

Reflex is a simple state container inspired by Rodux and Silo, designed to be an all-in-one solution for managing and reacting to state in Roblox games.

This package provides Reflex bindings for React using @rbxts/react-ts.

See the full documentation for Reflex here.

 

📦 Installation

$ npm install @rbxts/react-reflex
$ pnpm add @rbxts/react-reflex

 

📚 Usage

Reflex offers support for @rbxts/react-ts with @rbxts/react-reflex. Using react-reflex hooks requires setting up a ReflexProvider at the root of your Roact tree.

If you don't want to use generics to get the Producer type you want, Reflex exports the UseSelectorHook and UseProducerHook types to make it easier:

export const useRootProducer: UseProducerHook<RootProducer> = useProducer;
export const useRootSelector: UseSelectorHook<RootProducer> = useSelector;
export function App() {
	const { increment, decrement } = useRootProducer();

	const count = useRootSelector((state) => state.count);

	return (
		<textbutton
			Text={`Count: ${count}`}
			AnchorPoint={new Vector2(0.5, 0.5)}
			Size={new UDim2(0, 100, 0, 50)}
			Position={new UDim2(0.5, 0, 0.5, 0)}
			Event={{
				Activated: () => increment(),
				MouseButton2Click: () => decrement(),
			}}
		/>
	);
}
Roact.mount(
	<ReflexProvider producer={producer}>
		<App />
	</ReflexProvider>,
);

When using selector creators, you should avoid creating them in your render method (i.e. useSelector(selectPlayersOnTeam(redTeam))), since it creates a new selector every time the component renders and risks excessive re-renders. Instead, you can use the useSelectorCreator() hook to memoize the selector:

export const selectPlayersOnTeam = (team: Team) => {
	return createSelector([selectPlayers] as const, (players) => {
		return players.filter((player) => player.Team === team);
	});
};
const players = useSelectorCreator(selectPlayersOnTeam, redTeam);

 

📝 License

Reflex is licensed under the MIT License.

Keywords

FAQs

Package last updated on 08 Jul 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc