1.0.12 • Published 3 years ago
spake-react-sdk v1.0.12
How to use
spake-react-sdk is meant to be used in tandem with spake-cli to manage localized strings and set desired language.
- after strings localized strings have been generated via
spake-cli - wrap app with a
SpakeProvider - import
stringsandsetLangagefrom spake state and dispatch hooks
File Structure
SpakeProvider will look for json files in src/strings
src
-- strings
-- strings_en.json
-- strings_es.jsonExample
import React from 'react'
import SpakeProvider, { useSpakeState, useSpakeDispatch } from 'spake-react-sdk'
const App = () => {
return (
<SpakeProvider>
<Component />
</SpakeProvider>
)
}
const Component = () => {
const { strings } = useSpakeState()
const { setLanguage } = useSpakeDispatch()
return (
<>
<div>{strings.helloWorld}<div/>
<button onClick={() => {
setLanguage('es')
}}>Spanish<button/>
</>
)
}