0

i has a lot text in project so i make a js file just for text , and add this file to index.html , when use this file have error but when inspect code i can see text ,

faBundleForms.js

const forms = {
    changeProfitDate: {
        note_1: 'user ',
        note_2: 'add '
    }
};

add to index.html

`<script  src="../static/faBundleForms.js" type="text/javascript">`</script>

use to project

<p>{forms.changeProfitDate.note_1}</p>

i have this error

 'forms' is not defined
2
  • may be the url of the js file specified in the src attribute is incorrect Commented May 18, 2019 at 5:29
  • no i can see file in source of project Commented May 18, 2019 at 7:53

2 Answers 2

1

If you really want to use global variables (which is a bad idea), you need to use window. before them, like this: <p>{window.forms.changeProfitDate.note_1}</p>

Sign up to request clarification or add additional context in comments.

1 Comment

i use your recommend but i have this Error now: "TypeError: Cannot read property 'changeProfitDate' of undefined"
0

If you are using react the correct way seems to be something like this :
your text holding file :

export const text = ". . . lots of blah . . . "
export const text2 = ...

and you can import this file in your react project anywhere

import { text } from './yourTextFile'
const App = (props) => {
    return(
        <div>
            <p>{text}</p>
        </div>
    )
}

export default App

1 Comment

tax for idea but i has alot of text and repeat text alot , i need a better way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.