Directionality
Knowledge of directionality is required.
A DirectionProvider
is available for controlling the direction of a target React component tree.
While not necessary to render at the root, since the default direction is inferred from the device,
it can be used to explicitly enforce a direction, like so.
#
Contextual directionThe value
prop can be used to dynamically change the direction of a provider based on a user
provided string. For example, say we have a message thread, and we want to swap between LTR and RTL
depending on what's being entered in an input field.
As demonstrated above, if the user is typing in English, the direction would be ltr
, otherwise, if
the user is typing in Arabic, the direction would be rtl
, so on and so forth.
#
Accessing the directionTo manually access the current direction, either from the document or a provider, use the
useDirection()
hook or withDirection()
HOC.
- Hook
- HOC