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.
import { JuliyaText } from '@oddmash/juliya/react';
<JuliyaText as="h1" locale="en">Read every line naturally.</JuliyaText>| Option | Required | Default | Purpose |
|---|---|---|---|
children | Required | - | Text or supported inline children |
as | Optional | span | Rendered element |
locale | Optional | ko | Language rules; React also reads the nearest Provider |
strategy | Optional | balanced | Balanced or greedy layout |
breakLongWords | Optional | true | Allow grapheme-safe splits for overlong words |
forcedBreaks | Optional | - | Source UTF-16 boundary offsets |
JuliyaProvider
Pass locale or validated configuration once for descendants. Explicit props override inherited settings.
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.
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.
| Option | Required | Default | Purpose |
|---|---|---|---|
text | Required | - | Source string for the hook |
locale | Optional | ko | Language rules; React also reads the nearest Provider |
strategy | Optional | balanced | Balanced or greedy layout |
breakLongWords | Optional | true | Allow grapheme-safe splits for overlong words |
forcedBreaks | Optional | - | Source UTF-16 boundary offsets |
initialForcedBreaks | Optional | [] | Uncontrolled initial forced boundaries |
onForcedBreaksChange | Optional | - | 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.
import { JuliyaSentenceText } from '@oddmash/juliya/react/server';
<JuliyaSentenceText locale="en">Read every line naturally.</JuliyaSentenceText>