我有一个iframe加载第三方小部件的。我只想iframe在页面加载后显示此内容,因为我不想减慢页面加载速度。我遵循了一篇中等文章,其中描述了如何执行此操作,但他们的解决方案不起作用,因为函数onload,finishLoading从未被调用
export default ({src, width, height}) => {
const [loading, stillLoading] = useState(true)
const finishLoading = () => {
alert('finished loading')
stillLoading(false)
}
...
return(
{loading ? '' :
<iframe
src={src}
width={width}
height={height}
scrolling="no"
onLoad={finishLoading}
>
className={`tpwidget flex-center-row`}>
</iframe>
}
)
}
Run Code Online (Sandbox Code Playgroud)
更新
通过使用 useEffect,我可以让 iframe 在其他所有事情之后加载(理论上),但我发现删除 iframe 完全提高了我的 PageSpeed 分数,并且仅在(使用 useEffect)之后加载 iframe 并没有太大的积极效果关于页面速度。
如果有帮助,域名是suddensask.com,第三方小部件是亚马逊广告。
My app has 5 components (screens), I am using stack navigation version 5, I need the headers for all screens except one screen, I tried to do this via option inside screens like this:
This is my code:
const Stack = createStackNavigator();
const MainStack = () => ({
return(
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="MyTabs" component={MyTabs} />
<Stack.Screen name="Direct" component={Direct} />
<Stack.Screen name="Like" component={Like} />
<Stack.Screen name="Search" component={Search} />
<Stack.Screen name="Home" component={Home} />
</Stack.Navigator>
</NavigationContainer>
)
)}
Run Code Online (Sandbox Code Playgroud) 我正在与 jekyll 合作制作一个网站。
我用 Ruby 构建了一个自定义目录插件。
这是代码:
require 'nokogiri'
module Jekyll
module TOCGenerator
TOC_CONTAINER_HTML = '<ul>%1</ul>'
def toc(html,op)
toc_top_tag = "h1"
item_number = 0
toc_html = ''
sub_url = html['url']
doc = Nokogiri::HTML(html['content'])
doc.css(toc_top_tag).each do |tag|
toc_html += create_level_html(sub_url, tag['id'], tag.text)
item_number += 1
end
return '' unless item_number > 0
if 0 < item_number
toc_table = TOC_CONTAINER_HTML
.gsub('%1', toc_html)
end
end
private
def create_level_html(url, anchor_id, tocText)
link = '<a href="%1#%2">%3</a>'
.gsub('%1', url)
.gsub('%2', anchor_id.to_s)
.gsub('%3', tocText)
'<li>%1</li>'
.gsub('%1', link) …Run Code Online (Sandbox Code Playgroud) 每次我组成反应组件我都会为它制作文件夹.我制作文件index.js和component.jsx
例如
??? App.js
??? component
? ??? index.js
? ??? Component.jsx
...
Run Code Online (Sandbox Code Playgroud)
指数 component/index.js
export default from './Component'
Run Code Online (Sandbox Code Playgroud)
写入实际反应组件Component.jsx.
但问题是当我尝试使用create-react-app和Component.jsx下面的导入构建应用程序时
import Component from './component'
Run Code Online (Sandbox Code Playgroud)
像这样发生错误
./src/component/index.js
Syntax error: Unexpected token, expected ; (1:20)
> 1 | export default from './Component'
| ^
2 |
Run Code Online (Sandbox Code Playgroud)
但如果我写这样的代码component/index.js效果很好.
import Component from './Component'
export default Component
Run Code Online (Sandbox Code Playgroud)
我第一次有什么问题index.js吗?
我试图在用户登录时重定向我的用户。但是我到目前为止发现的所有方法都不起作用。etg 我正在尝试使用 react router v6 来使用 useNavigate 功能。
但由于某种原因,我收到以下错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See react-invalid-hook-call for tips about how to …Run Code Online (Sandbox Code Playgroud) reactjs ×4
javascript ×2
ecmascript-6 ×1
gatsby ×1
iframe ×1
jekyll ×1
liquid ×1
pagespeed ×1
react-native ×1
react-router ×1
ruby ×1