首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正确使用FingerprintJS

正确使用FingerprintJS
EN

Stack Overflow用户
提问于 2022-09-01 18:15:03
回答 1查看 103关注 0票数 0

我还没有在React.js工作过,但我想用FingerprintJS编写一些应用程序。

代码语言:javascript
复制
    function App() {
  let app_visitorId = 'Is not defined still';
  (async () => {
    // Get the visitor identifier when you need it.
    const fp = await fpPromise
    const result = await fp.get()
    // This is the visitor identifier:
    const visitorId = result.visitorId;
    const confidence = result.confidence;
    console.log(
        '----------------------------------------------------------\n' +
        'fingerprintjs@ visitorId: ' + visitorId + '\n' +
        'fingerprintjs@ confidence: ' + confidence.score.toPrecision(6) + '\n' +
        '----------------------------------------------------------\n');
  })();
  return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <p>
            Edit <code>src/App.js</code> and save to reload.<br/>
            {app_visitorId}
          </p>
          <a
              className="App-link"
              href="https://reactjs.org"
              target="_blank"
              rel="noopener noreferrer"
          >
            Learn React
          </a>
        </header>
      </div>
  );
}

我的问题是:如何更改'app_visitorId‘let以在呈现块中呈现其值?谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-05 08:24:13

useEffect钩子中,使用setStatevistitorId存储到状态。在呈现(返回函数)中,检查状态变量是否已经填充,因为返回的值来自异步承诺。如果是,则呈现visitorId

您可以在Next.js上使用GitHub检查更复杂的代码解决方案(但概念与with相同)。或者,可以检查指纹Pro反应库

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73573841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档