DocsFrameworks

React and Next.js

Set the active language once with JuliyaProvider. JuliyaText and useJuliya inherit it unless their own locale is specified. With no provider, Korean remains the default. Map your application's i18n language tags to ko, en, ja, zh or zh-Hans. Import the provider and consumers from the same package.

JuliyaText

Render text with an explicit element via as. The component measures client width; ordinary JSX and inline strings are appropriate.

tsx
import { JuliyaText } from '@oddmash/juliya/react';
<JuliyaText as="h1" locale="en">Read every line naturally.</JuliyaText>
OptionRequiredDefaultPurpose
childrenRequired-Text or supported inline children
asOptionalspanRendered element
localeOptionalkoLanguage rules; React also reads the nearest Provider
strategyOptionalbalancedBalanced or greedy layout
breakLongWordsOptionaltrueAllow grapheme-safe splits for overlong words
forcedBreaksOptional-Source UTF-16 boundary offsets

JuliyaProvider

Pass locale or validated configuration once for descendants. Explicit props override inherited settings.

tsx
import { JuliyaProvider, JuliyaText } from '@oddmash/juliya/react';

<JuliyaProvider locale="en">
  <JuliyaText as="h1">Read every line naturally.</JuliyaText>
</JuliyaProvider>

Connect i18n

Map application language tags to ko, en, ja, zh or zh-Hans and re-render the Provider when language changes.

Dynamic text

Pass new children; the component recomputes from the updated source without manually changing DOM.

Inline JSX

Supported links and emphasis retain semantics. Use an externally owned scope for trusted rendered HTML.

useJuliya

The hook returns ref, lines, measured, locale and forced-break controls. Attach the ref to a measurable element and render lines yourself.

tsx
import { Fragment } from 'react';
import { useJuliya } from '@oddmash/juliya/react';

const { ref, lines, locale } = useJuliya({ text, locale: 'en' });
return <p ref={ref} lang={locale} style={{ whiteSpace: 'pre-wrap' }}>{lines.map((line, index) => <Fragment key={line.start}>{line.text}{line.breakAfter || (index < lines.length - 1 ? <br /> : null)}</Fragment>)}</p>;

Hook options

Pass text, locale, strategy, breakLongWords and forcedBreaks as appropriate. Width is measured in the browser.

OptionRequiredDefaultPurpose
textRequired-Source string for the hook
localeOptionalkoLanguage rules; React also reads the nearest Provider
strategyOptionalbalancedBalanced or greedy layout
breakLongWordsOptionaltrueAllow grapheme-safe splits for overlong words
forcedBreaksOptional-Source UTF-16 boundary offsets
initialForcedBreaksOptional[]Uncontrolled initial forced boundaries
onForcedBreaksChangeOptional-Controlled boundaries callback

Controlled and uncontrolled

Use forcedBreaks to control positions externally, or initialForcedBreaks and the setters for local state.

Next.js App Router

Client components measure after hydration; JuliyaSentenceText can group source sentences in Server Components with an explicit locale.

tsx
import { JuliyaSentenceText } from '@oddmash/juliya/react/server';

<JuliyaSentenceText locale="en">Read every line naturally.</JuliyaSentenceText>