Skip to content

Add Dict component #1

@markusjwetzel

Description

@markusjwetzel

Let's assume we have defined the following dictionary dict:

const dict = createDict({
  hello: 'Hello {count}',
});

Currently we access a dictionary entry like this:

<Trans {...dict('hello', { count })} />

The downside of this approach is that function calls (at least those who do not create a JSX element) invalidates Flow type refinements: https://flow.org/en/docs/lang/refinements/#toc-refinement-invalidations

Because of that it might be an improvement to use a Dict function instead. Also you can say that this would be more a React like approach, because we use pure JSX.

import React from 'react';
import { createDict } from 'intlized-components';

const Dict = createDict({
  hello: 'Hello {count}',
});

function Component() {
  return <Dict name="hello" values={{ count }} />;
}

Without values the new syntax would also be a little bit shorter:

<Dict name="hello" />
{/* vs. */}
<Trans {...dict('hello')} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions